使用“conemon”这个词打印每个字符比上一个字符多2倍。第一个字母“c”应打印10次,第二个字母为12次,以此类推。每个重复的字母字符串都应该打印在新行上。
最终的结果是:
cccccccccc
oooooooooooo
nnnnnnnnnnnnnn
eeeeeeeeeeeeeeee
mmmmmmmmmmmmmmmmmm
oooooooooooooooooooo
nnnnnnnnnnnnnnnnnnnnnn发布于 2018-10-02 10:50:33
发布于 2018-10-02 10:54:53
v->{int i=8;for(var c:"conemon".split(""))System.out.println(c.repeat(i+=2));}在网上试试。 (注意:对于相同的字节计数,String.repeat(int)被模拟为repeat(String,int),因为Java11还没有在TIO上)。
v->{ // Method with empty unused parameter and no return-type
int i=8; // Integer `i`, starting at 8
for(var c:"conemon".split(""))
// Loop over the characters (as Strings) of "codemon"
System.out.println( // Print with trailing new-line:
c.repeat( // The current character repeated
i+=2));} // `i` amount of times, after we've first increased `i` by 2https://codegolf.stackexchange.com/questions/173159
复制相似问题