Discuss / Java / do while练习

do while练习

Topic source

凌翊CJV

#1 Created at ... [Delete] [Delete and Lock User]
/** * @author cjv * 测试do while */public class TestDoWhile {    public static void main(String[] args) {        /*使用do while循环计算从m到n的和。*/        int sum = 0;        int m = 20;        int n = 100;        // 使用do while计算M+...+N:        do {            sum += m;            m++;        } while (m <= n);        System.out.println(sum);    }}

  • 1

Reply