07、DoWhile循环

在这里插入图片描述

DoWhile题目一

package com.wzt.www.struct;

/**
 * @author WZT
 * @create 2021-03-24 21:12
 */
public class DoWhileDemo01 {
    
    
    public static void main(String[] args) {
    
    
        //计算1+2+3...+100=?
        int i = 0;
        int sum = 0;
        do {
    
    
            i++;
            sum = i + sum;

        }while (i<100);
        System.out.println(sum);
    }
}

输出

5050

Process finished with exit code 0

DoWhile题目二(两个while的区别)

package com.wzt.www.struct;

/**
 * @author WZT
 * @create 2021-03-24 21:15
 */
public class DoWhileDemo02 {
    
    
    public static void main(String[] args) {
    
    
        int i = 0;
        while (i<0){
    
    
            System.out.println(i);
        }
        System.out.println("======================");

        do {
    
    
            System.out.println(i);

        }while (i<0);
    }
}

输出

======================
0

Process finished with exit code 0

猜你喜欢

转载自blog.csdn.net/weixin_45809838/article/details/115194575