In: Computer Science
write a java code to calculate
1+2-3+4-5 …-99+100
import java.io.*;
class Main {
public static void main (String[] args) {
int num,sum=0;
for(num=1;num<=100;num++){
if(num%2==1){
sum=sum-num;
}
else{
sum=sum+num;
}
}
System.out.println("sum of series :
"+sum);
}
}