07 do···while循环

do···while 循环

  • 代码
package com.zhan.base_2;

public class Test07_DoWhile {
    public static void main(String[] args) {
        //输出 1+2+3+···+100总和
        int i=0;
        int sum=0;
        do{
            sum+=i;
            i++;
        }while(i<=100);
        System.out.println(sum);
        System.out.println("========================================");

        // while 和 do while 的区别
        int a=0;
        while (a<0){
            a++;
            System.out.println(a);
        }
        System.out.println("-----------");
        do {
            a++;
            System.out.println(a);
        }while (a<0);

        }
}
posted @ 2023-01-22 13:43  被占用的小海海  阅读(19)  评论(0编辑  收藏  举报