条件就是a%2==1
和a%2==0.
package cn.bdqn.demo02;
public class Zuoye6 {
public static void main(String[] args) {
int sum = 0;
int a = 1;
for(int i=1;i<=101;i+=2){
if(a%2==1){
sum=sum+i;
}else{
sum=sum-i;
} a++;
}
System.out.println("1-3+5-7+9...101="+sum);
}
}