public class Test1 {
public static void main(String args[]){
int n = 10;
int rst = getResult(n);
System.out.println(n+”的执行结果:”+rst);
}
public static int getResult(int n){
int result = 0;
for(int i=1;i<=n;i++){
switch(i%2){
case 0:result -=i;
break;
case 1: result += i;
break;
}
}
return result;
}
}