java - 麻烦老师解读一下这段代码的意思?
PHP中文网
PHP中文网 2017-04-18 10:38:54
0
1
372
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
刘奇

First reorganize the code. . .

class Demo{
    public static void main(String[] args){
        int x = 0;
        /* 当 x < 4 时执行循环,x >= 4 后跳出循环 */
        while (x < 4) {
            /* 输出 a */
            System.out.print("a");
            /* 如果 x < 1, 输出空格 */ 
            if (x < 1) {
                System.out.print(" ");
            }
            /* 输出 n  */ 
            System.out.print("n");
            /* 如果 x > 1, 输出 oyster, 并且 x 被加 2 */ 
            if(x > 1) {
                System.out.print(" oyster");
                x = x + 2;
            }
            /* 如果 x 等于 1, 输出 noys */ 
            if(x == 1) {
                System.out.print("noys");
            }
            /* 如果 x < 1, 输出 oise */ 
            if(x < 1) {
                System.out.print("oise");
            }
            System.out.println("");
            /* x 加 1*/ 
            x=x+1;
        }
    }
}

In the first loop, x equals 0, execute line 7, output a, execute line 10, output a space, execute line 13, output n, then
execute line 25, output oise, line 27 wraps, and then add x to 1 becomes 1.

In the second loop, x equals 1, execute lines 7, 13, 21, and 27, output annoys, and then add 1 to x to become 2.
The third cycle, the fourth cycle you can study by yourself. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!