Computer Science, asked by sohamtribedi548, 9 months ago

Write a Java Program to find the sum of the given series:- S=2-4+6-8+........upto n​

Answers

Answered by bhoopbhoomi3088
3

Answer:

public class SumOfSeries{

public static void main(String args[]){

int n = 20;int sum =0;

for(int i=2;i<=n;i=i+2){

if(i%4==0){ sum=sum-i;}

else{ sum=sum+i;}

Similar questions