print the series 2+4+6+8+...n using java

  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);

Comments

Popular posts from this blog