Discuss / Java / 作业

作业

Topic source

吕归尘丶

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

  • 1

Reply