- Access the routines for the Scanner
- class Main
- method main
- Create the Scanner object for the keyboard
- Intialize the variables for the sums
- Initialize number strings
- Ask the user how many numbers they will enter
- Ask if a number is even
- Read in a number typed on the keyboard and store it in a variable
- Prompt the user to enter a number
- Add a number to the sum of all even numbers
- Concatenate a number to the string of all even numbers.
- Repeat the following code "total" times
- Increment the counter for how many even numbers have been entered
- Declare and initialize a variable for the average
- Calculate an average
- Display a sum and average
|
- public static void main
- int total = scan.nextInt();
- System.out.print("Enter the total number of values to enter: ");
- import java.util.Scanner;
- if (num % 2 == 0 )
- int sumEven=0; int sumOdd = 0;
- int num = scan.nextInt( );
- Scanner scan = new Scanner(System.in);
- public class Main
- sumEven = sumEven + num;
- for (int n = 1; n<= total; n++){
- String numberStringEven="";String numberStringOdd = "";
- if(countOdd > 0) avgOdd = sumOdd / countOdd;
- System.out.print("Enter number "+ n + ": ");
- numberStringEven = numberStringEven + num;
- double avgOdd = 0.0;
- System.out.println("The total of the odd numbers is " + sumOdd +", the average is " + avgOdd);
- countEven = countEven + 1;
|