package Day09;
/*计算1+2-3+4-5……+100*/
public class Work02 {
public static void main(String[] args) {
int sum=1;
for (int i = 2; i <=100; i++) {
if(i%2==0){
sum+=i;
}else{
sum-=i;
}
}
System.out.println (sum);
}
}
/*计算1+2-3+4-5……+100*/
最新推荐文章于 2023-07-24 20:43:07 发布