public int returnSum(int n){
int sum=0;
for(int i=1;i<=n;i++){
int k=i;
if(k%2==0){
k=-k;
}
sum+=k;
}
return sum;
}
时间: 2024-11-07 09:36:29
public int returnSum(int n){
int sum=0;
for(int i=1;i<=n;i++){
int k=i;
if(k%2==0){
k=-k;
}
sum+=k;
}
return sum;
}