Discuss / Java / 封装函数写的,诡异的输出打印~~~

封装函数写的,诡异的输出打印~~~

Topic source

_崔先生_

#1 Created at ... [Delete] [Delete and Lock User]

public static void m2n(int m, int n) {

// System.out.println((m+n)*(Math.abs(m-n)+1)/2);
    if(m > n) {
int t = m; m = n; n = t;
        }
    System.out.print(m);
int sum = 0;
while (m <= n){
        sum += m;
        m++;
        }
    System.out.print(String.format("+...+%d=%d", n, sum));
    }
}


  • 1

Reply