[Solved] addition of positive and negative numbers


The first println is trying to say I’m gonna sum numbers from 1 to 10 but be careful to add the even numbers as negative numbers

So as the even numbers are negative, The code is trying to first check if it’s an even number by

(j % 2 == 0)

If it’s an even then it multiply the number by -1 in order to create a negative even number,

 x = -1 * j;

otherwise(odd number) it use the exact number,

x = j;

Finally it add up all the numbers

sum = sum + x;

solved addition of positive and negative numbers