php開發(fā)

循環(huán) while:


馬克- to-win:馬克 java社區(qū):防盜版實名手機(jī)尾號: 73203。
馬克-to-win:當(dāng)while(i<4),當(dāng)i<4時,一直執(zhí)行括號里的東西,當(dāng)執(zhí)行到右大括號,回到while判斷一下,條件成立,繼續(xù)執(zhí)行。
例1:
public class Test45 {
    public static void main(String[] args) {
        int i = 0;
        while (i < 2) {
            System.out.println(i);
            System.out.println("你好");
            i++;
        }
    }
}
結(jié)果:
0
你好
1
你好




例2:打印從3到6

public class Test46 {
    public static void main(String[] args) {
        int i = 3;
        while (i < 7) {
            System.out.println(i);
            i++;
        }
    }
}
結(jié)果:
3
4
5
6



作業(yè)1:馬克-to-win:打印年級1-6,假如i==3打印練太極,假如i==4,打印美術(shù),假如i==5打印跳舞

public class Test47 {
    public static void main(String[] args) {
        int i = 1;
        while (i < 7) {
            System.out.println(i);
            if (i == 3) {
                System.out.println("練太極");
            }
            if (i == 4) {
                System.out.println("美術(shù)");
            }
            if (i == 5) {
                System.out.println("舞蹈");
            }
            i++;
        }
    }
}
結(jié)果:
1
2
3
練太極
4
美術(shù)
5
舞蹈
6



作業(yè)2:閱讀

public class Test48 {
    public static void main(String[] args) {
        int i = 1;
        while (i < 7) {
            if (i < 5 && i > 3)

            {
                System.out.println(i + "中高年級");
            }
            i++;
        }
    }
}
結(jié)果:
4中高年級



作業(yè)1:馬克-to-win:打印年級1-6,假如i==3打印練太極,假如i==4,打印美術(shù),假如i==5打印跳舞

public class Test47 {
    public static void main(String[] args) {
        int i = 1;
        while (i < 7) {
            System.out.println(i);
            if (i == 3) {
                System.out.println("練太極");
            }
            if (i == 4) {
                System.out.println("美術(shù)");
            }
            if (i == 5) {
                System.out.println("舞蹈");
            }
            i++;
        }
    }
}
結(jié)果:
1
2
3
練太極
4
美術(shù)
5
舞蹈
6