出第一道关于for循环的题,理想输出结果如下:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
先不要看下面的答案,自己想一想,理一理思路。最好能写出你的解题思考逻辑。
顺便检测一下自己对嵌套循环的掌握程度。
public class Welcome
{
public static void main(String[] args)
{
for(int i=1; i<10; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print(j + " ");
}
System.out.println();
}
}
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
先不要看下面的答案,自己想一想,理一理思路。最好能写出你的解题思考逻辑。
顺便检测一下自己对嵌套循环的掌握程度。
public class Welcome
{
public static void main(String[] args)
{
for(int i=1; i<10; i++)
{
for(int j=1; j<=i; j++)
{
System.out.print(j + " ");
}
System.out.println();
}
}
}