-3

非常に単純ですが、理解できないようです。while ループを do-while に変換するだけです。目的は、1-9 と 9-1 を "1,22,333,4444" などとして印刷することです。

int y = 1;
int x = 1;
while (x < 10) {
    y = 1;
    while (y <= x) {
        y++;
        System.out.print(x + "");
    }
    System.out.println();
    x++;
}

int a = 9;
int b = 1;
while (a >=1) {
    b = 1;
    while (b<= a) {
        b++;
        System.out.print(a + "");
    }
    System.out.println();
    a--;
}

私の試みは 1-9 を出力しますが、単一の数字として無限に実行されますが、最初は 9 以降は何も出力しません。

int c = 1;
int d =1;
do { System.out.print(c +"");
c++;
System.out.println();
}
while (c<10);{
    y=1;
    while (d<=c);
}
4

5 に答える 5

0

これは基本的な使い方です:

x=1;
do{ 
    //hello
    x++; 
} while(x<=10); 

必要に応じて適用してください。私たちは本当にあなたの宿題をすることができません.

于 2013-10-02T14:59:32.370 に答える
0

無限ループで実行したいので、次を使用してください:

    do {
        int c = 1;
        do {
            System.out.println(c);
            c++;

        } while (c < 10);
    } while (true);
于 2013-10-02T15:02:36.230 に答える
0

Looks like we are doing your homework...

public class Test {
    public static void main(String[] args) {
        int c = 1;
        do { 
            int d =1;
            do{
                System.out.print(c);
                d++;
            } while (c>=d);
            System.out.println("");
        c++;        
        }
        while (c<10);
    }
}
于 2013-10-02T15:05:44.210 に答える