print the series 2+4+6+8+...n using java Get link Facebook X Pinterest Email Other Apps - April 01, 2021 int a=2,n=10; // n for number of terms //a is the starting value int sum=0; for(int i=1;i<=n;i++) { sum=sum+a; a=a+2; } System.out.println(sum); Read more
print the series 2-4+6-8+10.....n using java Get link Facebook X Pinterest Email Other Apps - April 01, 2021 int a=2,n=10; // n for number of terms //a is the starting value int sum=0; for(int i=1;i<=n;i++) { if(i%2==0) { sum=sum-a; } else { sum=sum+a; } a=a+2; } System.out.println(sum); Read more