Anonymous

Write a Java program to find the sum of 1+3+5+…. for 10 terms in the series?

2

2 Answers

Yo Kass Profile
Yo Kass answered

I posted this question in an awesome Java G+ Community and that lead me to the following answer:

int x;
int i;

for (i = 0; i < 10;i ++)
{
x = x +(i*2)+1;
}

an alternative suggestion was:

class test{
public static void main(String args[]){
int i=0;
int x=0;
int j=1;

for (i=0;i<10;i++)
{
x=x+j;
j=j+2;
}

System.out.println("Answer is "+x);

}
}

Anonymous Profile
Anonymous answered

class test{
public static void main(String args[]){
int i=0;  //For Loops
int x=0; //For Total
int j=1;  //For Series of Numbers

for (i=0;i<10;i++)
{
x=x+j;
j=j+2;
}

System.out.println("Answer is "+x);

}
}

Answer Question

Anonymous