Q:

Java Program Calculation

Write a program in Java to calculate the following:
   1+2-3+4-5 …-99+100
this program is provably very simple but I am a beginner to java and this is what i have so far I'm not sure if i am in the right path 
I get one java: 13 error message error:not a statement sub;
class Loop{
    public static void main(String[] args){
        int sum=0;
        int sum=0;
        int sub=0;

        while(num<100){

            num++;
            if(num%2 == 0){
                sum=sum+num;
            }
            sub;
            if(num%3== 0||num%5==0||num%7==0){
                sub=sub-num;
            }
        }
        System.out.println("Sum is: " +sum+sub);
    }
}

A:

You can using simple way to implement it :
 public static void main(String[] args) {
    int sum = 1;
    for (int i = 2; i < 100; i++) {
        if (i % 2 == 0) {
            sum = sum + i;
        } else {
            sum = sum - i;
        }
    }
    System.out.println(sum);
}

