package javaapplication1;
public class JavaApplication1 {
/**
* Repeat string <b>str</b> <b>times</b> time.
* @param str string to repeat
* @param times repeat str times time
* @return generated string
*/
public static String repeat(String str, int times) {
return new String(new char[times]).replace("\0", str);
}
public static void main(String[] args) {
System.out.println(repeat("*", 5));
}
}
-
-
Save abdullah-alialdin/6307af6b5fa52889fc348275061a2af2 to your computer and use it in GitHub Desktop.
Repeat string N times without loop in Java
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment