2011-04-12 23 views

回答

6
System.out.println("hello hello hello hello hello"); 
+1

打印「hello」5次,空格4次:) – khachik 2011-04-12 19:35:18

+0

@khachik:空格被添加了清晰度;-) – darioo 2011-04-12 19:36:11

+0

對不起有it.using遞歸函數也可以打印...靜態無效REC(INT N){ \t \t如果(N == 0) \t \t \t回報; \t \t System.out.println(「hello」); (n-1); \t \t rec(n-1); \t} – Sri 2011-04-12 19:38:44

1

你可以用遞歸來做到這一點。這是功課嗎?聽起來像是這樣,所以除非另有說明,否則我不會給出完整的答案。

+0

我同意,但這不是一個答案,聽起來更像是一個評論 – BlackBear 2011-04-12 19:52:27

+0

我覺得這是一個答案,它指出OP在正確的方向。這比其他諷刺性的答案更重要。 – mdma 2011-04-12 20:28:30

0
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)); 
相關問題