a
我到处搜索过,并且无法弄清楚如何在java中使用嵌套for循环创建输出。
一直持续到z
这就是我所尝试的
String alphabet =abcdefghijklmnopqrstuvwxyz ; $ p $ for(int i = 0; i <= 25; i ++) { for(char j =(char)(alphabet.charAt(i)); j
请帮我!
for(int x ='a')解决方案; x <='z'; x ++) { for(int i ='a'; i <= x; i ++) { System.out.print (炭)ⅰ); } System.out.println(); $ p $ b $外部循环从一行切换到另一行,循环打印该特定行的字符。
I have searched everywhere and I cannot figure out how to create this output using a nested for loop in java:
"a
ab
abc
abcd"
continued until z
this is what I have tried
String alphabet = "abcdefghijklmnopqrstuvwxyz";
for(int i = 0; i <= 25; i++) { for(char j = (char)(alphabet.charAt(i)); j<=i; j++) { System.out.print(j); } System.out.println(); }Please help me!
解决方案Here is the answer:
for (int x = 'a'; x<='z'; x++) { for (int i = 'a'; i<=x; i++) { System.out.print((char)i); } System.out.println(); }The outer loop switches from one row to another whilst the inner loop prints the characters for that particular row.