do while循环

do while循环

package test.operator;
public class doWhileDemo03 {
    public static void main(String[] args) {
        //while和do while的区别
        int i = 0;
        while(i<0){
            System.out.println(i);
        }
        
        System.out.println("===========");

        do{
            System.out.println(i);
        }while(i<0);
    }
}
package test.operator;
public class doWhileDemo02 {
    public static void main(String[] args) {
        //计算1+2+3...+99+100的和
        int i = 1;
        double sum = 0;
        do{
            sum = sum + i;
            i++;
        }while(i<=100);
        System.out.println(sum);
    }
}
package test.operator;
public class doWhileDemo01 {
    public static void main(String[] args) {
        //输出1-100的数字
        int i= 1;
        do{
            System.out.println(i);
            i++;
        }while(i<=100);
    }
}
posted @ 2023-02-14 19:06  chengh0618  阅读(12)  评论(0编辑  收藏  举报