Question: Write a Java program that will input integer values from the user. The user will enter a sequence of integer values in a loop that

Write a Java program that will input integer values from the user. The user will enter a sequence of integer values in a loop that will go for maximum 10 iterations (declare a class constant for 10) but it will stop if the user is entering a negative value. The program computes the sum and the average of all positive numbers in the sequence. HINT: You will need to implement a loop that is both count-controlled (has up to 10 iterations) and event-controlled (stops earlier if a negative value is entered).

OUTPUT (3 SAMPLES): SAMPLE #1 Enter a number, negative to STOP: 1 Enter a number, negative to STOP: 2 Enter a number, negative to STOP: 3 Enter a number, negative to STOP: 4 Enter a number, negative to STOP: 5 Enter a number, negative to STOP: 6 Enter a number, negative to STOP: -8 =============================== You entered 6 positive numbers. The sum = 21 The average = 3.50

SAMPLE #2 Enter a number, negative to STOP: -1 ERROR! Division by 0. No input.

SAMPLE #3 Enter a number, negative to STOP: 1 Enter a number, negative to STOP: 2 Enter a number, negative to STOP: 3 Enter a number, negative to STOP: 4 Enter a number, negative to STOP: 5 Enter a number, negative to STOP: 6 Enter a number, negative to STOP: 7 Enter a number, negative to STOP: 8 Enter a number, negative to STOP: 9 Enter a number, negative to STOP: 10 ================================ You entered 10 positive numbers. The sum = 55 The average = 5.50

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!