Discuss / Java / 打卡打卡

打卡打卡

Topic source

xiao伟iii

#1 Created at ... [Delete] [Delete and Lock User]
package com.itranswarp.learnjava;

/**
 * while练习
 */
public class Main {

	public static void main(String[] args) {
		int sum = 0;
		int m = 20;
		int n = 100;
		System.out.println(((m + n) * (n - m + 1)) / 2);
		// FIXME: 使用while计算M+...+N:
		while (m <= n) {
			sum += m;
			m ++;
		}
		System.out.println(sum);
	}

}

  • 1

Reply