WAP to print the sum of the series in JAVA:
1 - 3 + 5 - 7 + 9 ........... (n).
Answers
Answered by
4
inport java.util.*;
class sum
{
public static void main()
{
Scanner s=new Scanner(System.in);
System.out.println("input value of n");
int n=s.nextInt();
int a,sum=0;
for(a=1;a<=n;a+=2)
{
if(a%2==0)
sum=sum+a;
else
sum=sum-a;
}
}
}
HOPE IT HELPS......
PLZ MARK BRAINLIEST
Similar questions