java流程控制之 while 循环

package struct;

public class Demo04 {
    public static void main(String[] args) {
        text();

        text2();

        text3();
    }

    public static void text() {
        int i = 0;
        int sum = 0;

        do {
            sum += i;
            i++;
        } while (i <= 100);
        System.out.println(sum);//5050
    }


    public static void text2() {
        int a = 10;

        while (a < 10) {
            System.out.println(a);//不进这个循环
            a++;
        }

        System.out.println("-----------------");

        do {
            System.out.println(a);//10
            a++;
        }while (a<10);
    }


    public  static  void  text3(){
        int a=1;
        while (a<100){
            System.out.println(a);
            a+=2;
        }
        System.out.println("while循环结束");

        for (int i = 1; i < 100; i+=2) {
            System.out.println(i);
        }
        System.out.println("for循环结束");


    }
}


posted @ 2021-07-29 09:43  阿向向  阅读(52)  评论(0编辑  收藏  举报