While与do...While

While与do...While

public class WhileDemo01 {
    public static void main(String[] args) {
        //输出1-100

        int i = 0;
        while (i<100){
            i++;
            System.out.println(i);
        }
    }
}


public class WhileDemo02 {
    public static void main(String[] args) {
        //死循环
        while (true){
            //等待客户端连接
            //定时检查
            //。。。。
        }
    }
}


public class WhileDemo03 {
    public static void main(String[] args) {
        //计算1+2+3+...+100;

        //高斯的故事

        int i = 0;
        int sum = 0;

        while (i<=100){
            sum = sum + i;
            i++;
        }

        System.out.println(sum);
    }
}


public class DoWhileDemo01 {
    public static void main(String[] args) {
        int i = 0;
        int sum = 0;

        //i++和++i的区别
        do {
            sum = sum + i;
            i++;
        }while (i<=100);

        System.out.println(sum);
    }
}


public class DoWhileDemo02 {
    public static void main(String[] args) {
        int a = 0;
        while (a<0){
            System.out.println(a);
            a++;
        }
        System.out.println("===============");
        do{
            System.out.println(a);
            a++;
        }while (a<0);
    }
}

do while与while的区别

posted @ 2020-07-06 15:53  小卢传  阅读(82)  评论(0编辑  收藏  举报