如何在 java 中用 while 循环叠加数字模式?

How can I stack up the number patterns with while loop in java?

尊敬的专业人士! 我是编程的超级初学者 java。 我只是在学校学习一些基本的东西。 我在做作业的时候遇到了一个问题

问题是使用嵌套循环制作这个堆叠数字模式:

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
1 2 3 4 5 6 7 8 9 10

我只能用while循环(因为我们还没有学过for循环和do循环),外层循环体要执行10次。 我可以使用 print 和 println 来制作这个图案。

我用 while 循环尝试了很多不同的方法,但我想不通。

拜托,请给我一些提示。

这是我目前正在处理的代码:

class C4h8
{
    public static void main(String[] args)
    {
        int i, j;

        i = 1;
        while(i <= 10)
        {
            j = 1;
            while (j <= 10)
            {

                System.out.print(j);
                j++;

            }


            System.out.println();
            i++;

        }

    }
}

但它只显示:

12345678910
12345678910
12345678910
12345678910
12345678910
12345678910
12345678910
12345678910
12345678910
12345678910

我的问题可能看起来很愚蠢,但我真的很纠结,因为就像我提到的,我是一个超级初学者.. 请帮助我,以便我可以学习并继续前进!

非常感谢!

使用如下:你需要通过变量i限制变量j来实现你的输出

class C4h8
{
    public static void main(String[] args)
    {
        int i, j;

        i = 1;
        while(i <= 10)
        {
            j = 1;
            while (j <= i) // limit the variable j by i 
            {

                System.out.print(j+" ");
                j++;

            }

            System.out.println();
            i++;

        }
    }
}

while 循环代码更少

int i = 0;
int limit = 10;
while(++i <= limit){
    int j = 0;
    while(++j <= i)
        System.out.print(j+" ");
    System.out.println();
}