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
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
CBSE BOARD X,
4 months ago
English,
4 months ago
Math,
9 months ago
History,
9 months ago
English,
1 year ago