Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

How do I loop it?

$
0
0
Write a method named repl that accepts a String and a number of repetitions as parameters and returns the String concatenated that many times. For example, the call repl("hello", 3) returns "hellohellohello". If the number of repetitions is 0 or less, an empty string is returned.

I can only loop 1 time only. May I know what is the problem?

public static String repl (String i, int j){
    for (int k = 0; k<j; k++){
    }
    return i; 
}
public static void main (String [] args){
  String i = repl ("hello", 3);
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>