rugk
0
Q:

how to write a method that returns a string that copies itself times n

string result = new String('-', 5);
Output: -----
2
public static String repeat(String s, int n) {    StringBuilder sb = new StringBuilder(str.length() * n);    for (int i = 0; i < n; i++)        sb.append(s);    return sb.toString();} public static void main(String[] args) {    System.out.println(repeat("ha", 5));}
0

New to Communities?

Join the community