public class TestLoop {
public static void main(String[] arguments){
int [] a=new int[10];
for(int i=0;i<10;i++){
System.out.print("@");
for(int j=0;j<3;j++)
System.out.print("*");
a[i]=i;
System.out.println(a[i]);
for(int p=0;p<4;p++)
System.out.print("P");
for(int k=0;k<3;k++)
System.out.print("K");
for(int m=0;m<3;m++)
System.out.print("U");
for(int n=0;n<5;n++)
System.out.print("N");
}
}
}/*结果:@***0
PPPPKKKUUUNNNNN@***1
PPPPKKKUUUNNNNN@***2
PPPPKKKUUUNNNNN@***3
PPPPKKKUUUNNNNN@***4
PPPPKKKUUUNNNNN@***5
PPPPKKKUUUNNNNN@***6
PPPPKKKUUUNNNNN@***7
PPPPKKKUUUNNNNN@***8
PPPPKKKUUUNNNNN@***9
PPPPKKKUUUNNNNN
*/
运行的结果第一行怎么是这样的,不明白。
public static void main(String[] arguments){
int [] a=new int[10];
for(int i=0;i<10;i++){
System.out.print("@");
for(int j=0;j<3;j++)
System.out.print("*");
a[i]=i;
System.out.println(a[i]);
for(int p=0;p<4;p++)
System.out.print("P");
for(int k=0;k<3;k++)
System.out.print("K");
for(int m=0;m<3;m++)
System.out.print("U");
for(int n=0;n<5;n++)
System.out.print("N");
}
}
}/*结果:@***0
PPPPKKKUUUNNNNN@***1
PPPPKKKUUUNNNNN@***2
PPPPKKKUUUNNNNN@***3
PPPPKKKUUUNNNNN@***4
PPPPKKKUUUNNNNN@***5
PPPPKKKUUUNNNNN@***6
PPPPKKKUUUNNNNN@***7
PPPPKKKUUUNNNNN@***8
PPPPKKKUUUNNNNN@***9
PPPPKKKUUUNNNNN
*/
运行的结果第一行怎么是这样的,不明白。
int[] a = new int[10];
for (int i = 0; i < 10; i++) {
System.out.print("@");
for (int j = 0; j < 3; j++)
System.out.print("*");
a[i] = i;
System.out.print(a[i]); // 这里不要换行
for (int p = 0; p < 4; p++)
System.out.print("P");
for (int k = 0; k < 3; k++)
System.out.print("K");
for (int m = 0; m < 3; m++)
System.out.print("U");
for (int n = 0; n < 5; n++)
System.out.print("N");
System.out.println(); // 这里换行
}
}
System.out.print("*");
第一次循环进来 先打印一个 @然后遇到上面这个循环, 就连续打印 三个*了
之后是 a[i]=i;
System.out.println(a[i]); 打印一个 a[i] (0) 换行, 所以 就是 你的执行结果了,
不知道你想 要什么样的结果哪?
俺也是来学习滴,一起努力!up^up