write a program to find the summ of following series S=1-2+3-4+5-6+.....+19-20
Answers
Answered by
1
Answer:
public class Main
{
public static void main(String[] args) {
int sum=1;
boolean isMinus=true;
for (int i=2;i<=20 ;i++ )
{
if(isMinus)
{
sum=sum-i;
isMinus=false;
}
else
{
sum=sum+i;
isMinus=true;
}
}
System.out.println(sum);
}
}
Explanation:
Here's the Java program
Similar questions