Discuss / Java / 作业

作业

Topic source

吕归尘丶

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

  • 1

Reply