Question: Write a method called printAverage that uses a sentinel loop to repeatedly prompt the user for numbers. Once the user types any number less than

Write a method called printAverage that uses a sentinel loop to repeatedly prompt the user for numbers. Once the user types any number less than zero, the method should display the average of all nonnegative numbers typed. Display the average as a double. Here is a sample dialogue with the user:

Type a number: 7

Type a number: 4

Type a number: 16

Type a number: –4

Average was 9.0

If the first number that the user types is negative, do not print an average:

Type a number: –2

Step by Step Solution

3.23 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static void printAverage Systemoutprint Type a number Scan... View full answer

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 Building Java Programs A Back to Basics Approach Questions!