开发者

how to just print the statement without any loop condition in java?

开发者 https://www.devze.com 2023-02-23 22:40 出处:网络
I just want to print the \"hello\" 5 times without using for lo开发者_运维技巧op,while loop ?System.out.println(\"hello hello hello hello hello\");

I just want to print the "hello" 5 times without using for lo开发者_运维技巧op,while loop ?


System.out.println("hello hello hello hello hello");


You can do this with recursion. Is this homework? Sounds like it, so I'll not give a full answer unless you say otherwise.


public String repeat(String str, int times){
   return new String(new char[times]).replace("\0", str);
}
//...
String bob = "bob ";
System.out.println(repeat(bob, 5));
0

精彩评论

暂无评论...
验证码 换一张
取 消