Working out the odd/even problem in steps

=====Sum and average all of the odd and even numbers entered by the user.
When the program runs it should look like this:

How many numbers will you enter? 3
Enter number 1: 20
Enter number 2: 25
Enter number 3: 44

The odd numbers are 25
The total of the odd numbers is 25, the average is 25

The even numbers are 20 44
The total of the even numbers is 64, the average is 32

Step #4: Looping

So far the code looks like this:

  1. import the Scanner
  2. class Main
  3. method main
  4. Create the Scanner object for the keyboard
  5. Intialize the variables for the sums and number strings
  6. Ask the user how many numbers they will enter
  7. enter the numbers and add each one to either the odd or even sum and string

But our program needs a loop so it will ask for as many numbers as the user wants, not just one number.

Do you remember back at Step #1 where the user typed in a number, called total, to decide how many numbers will be entered and analyzed?

for (int n = 1; n<= total; n++){
     // prompt the user to enter number n
     // read in the number and call it num
     // add num to either sumOdd or sumEven
     // join num as a string to either numberStringEven or numberStringOdd 

 

<-- Previous