0

The following code is what I was able to create but now I'm confused on what to do next.

Write a program that reads a sequence of integer inputs and prints

  • The cumulative total of the numbers
  • The smallest of the inputted numbers
  • The largest of the inputted numbers
  • The number of even inputs
  • The number of odd inputs
  • The average of the numbers (you will need to track another piece of information for this)

The program should set up the input (Scanner) and variables first, then use a while loop that asks the user for input and keeps track of the data needed. A way must be specified for the user to stop inputs, perhaps by entering Q or q. When the loops ends, the program should print the results for the questions. The cumulative total of the numbers so far should be printed after each number that the user inputs. The smallest, largest, number of evens, number of odds and average need only be printed after the user has finished entering numbers.You will need if statements and modulus to complete this task. All numbers should be integers for this program. When you are finished, please turn in your commented code on Blackboard. Please be sure your name is commented at the top of your code.

    //Asks user of a number
    System.out.print("Enter an integer: ");
    int num = 0;

    int num1;
    int num2;
    int num3;
    int num4;
    int num5;

    while (in.hasNextInt())
        {
        num = in.nextInt();

        System.out.print("Enter next integer or Q to quit ");
        }

    //Gets total of numbers

    //Gets smallest number

    //Gets largest number

    //Number of even inputs

    //Number of odd inputs

    //Gets average of numbers
  • 1
    You should consider using an array or an arraylist(if you don't know the number of inputs the user is going to input). Also your while loop should not be `in.hasNextInt()` you should get String `in.next()` and parse to Integer and in your loop check the string and loop until the `string.equalsIgnoreCase("Q")`...Hopefully that is enough to get you started. – brso05 Nov 13 '14 at 13:47
  • 2
    I think it is part of the exercise to not use arrays (or other dynamic datastructures, at least in the way i read it) for this job. Also, you shouldn't call you ints `num1` to `num5`, instead give them speaking names like `commuilativeSum`. – Turing85 Nov 13 '14 at 13:51

0 Answers0