WAP to print the sum of the series 1-2+3-4.....n
Answers
Answered by
5
Answer:
static void main()
{ int s=0;
for(int I =1;i<=10;i++)
{if(i%2==0)
{s=s-i;
}
else
{
s=s+i;
}
}
System. out.println("sum is "+s);
}
Similar questions