求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m
private static int fun(int m) { int temp = 0; for (int i = 1; i <= m; i++) { if (i % 2 == 1) temp = temp + i; else temp = temp - i; } return temp; }
private static int fun(int m) { int temp = 0; for (int i = 1; i <= m; i++) { if (i % 2 == 1) temp = temp + i; else temp = temp - i; } return temp; }