Discuss / Java / while练习

while练习

Topic source

凌翊CJV

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

凌翊CJV

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

  • 1

Reply