cancel
Showing results for 
Search instead for 
Did you mean: 

Math problem

Former Member
0 Kudos

I am trying to figure out a math problem I was given for a work assignment:

Modify the program to add the squares of the odd numbers from 1 to 19. Your program must compute the sum 1² + 3² + 5² + ... + 19². Print the partial sum at the end of each iteration of the loop.Hand in a listing of your program along with the output from a run of the program. The following values should be printed.

1, 10, 35, 84, 165, 286, 455, 680, 969, 1330

Can anyone help me figure out the coding? This has been driving me crazy for days!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Jorden,

Here it is the loop, include it in your main method :

int sum = 0;

for (int i = 1; i <= 19; i =i+2) {

sum += i*i;

System.out.print(sum + " ");

}

HTH

Peter

Former Member
0 Kudos

Thank you very much