following is the question . /* Class StringHelper Write a class StringHelper, which will have 2 static methods: - String multiply(String s, int count) should return the string s repeated count times. - String multiply(String s) should return the string s repeated 5 times.

Example:
Amigo -> AmigoAmigoAmigoAmigoAmigo

*/ And i coded it like this . but didnt pass test . pleasue guide me .

public static String multiply(String s)
{
    String result = "";
    result = "Amigo"+"Amigo"+"Amigo"+"Amigo"+"Amigo";
    return result;
}

public static String multiply(String s, int count)
{
    String result = "";
    int n = 5;
    for(int i=0; i < n; i++) {
    result = result + "Amigo";
    }
    return result;
}

asked 01 May '15, 11:14

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
431921
accept rate: 0%


instead of using "Amigo" use s (which is the variable for the string you're passing to the method). "Amigo" is just an example if user enter the name Amigo after creating the object

link

answered 04 May '15, 16:34

rahul's gravatar image

rahul
796
accept rate: 15%

public class StringHelper
{
    public static String multiply(String s)
    {
        String result = "";
        for(int i = 0; i < 5; i++){
            result += s;
        }
        return result;
    }

    public static String multiply(String s, int count)
    {
        String result = "";
        for(int i = 0; i < count; i++){
            result += s;
        }
        return result;
    }
}
link

answered 19 May, 12:47

Igor's gravatar image

Igor
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×36
×11
×5

Asked: 01 May '15, 11:14

Seen: 1,308 times

Last updated: 19 May, 12:47