Computer Science, asked by gipsyjudu, 9 months ago

Write a program in java to display the series 1-2+3-4 using for loop. please give the answer fast ... useless answers will be reported

Answers

Answered by dhruvbh
1

Explanation:

class abc

{

public static void main(int n)

{

int i;

int sum=0;

for(int i=1;i<=n;i++)

{

if(i%2==0)

sum=sum-i;

else

sum=sum+i;

}

System.out.println("The Sum is "+sum);

}

}

Similar questions