Question: Write your code in the file TwoSmallest.java , your file has to have this exact name with T and S capitalized. You must use the

Write your code in the file TwoSmallest.java, your file has to have this exact name with T and S capitalized. You must use the IO module to read inputs and to output your answers.

Write a program that takes a set of numbers and determines which are the two smallest numbers.

Ask the user for the following information, in this order:

A terminating value (real number). The user will enter this value again to indicate that he or she is finished providing input.

A sequence of real numbers. Keep asking for numbers until the terminating value is entered.

Compute and output the smallest and second-smallest real number, in that order. It is possible for the smallest and second-smallest numbers to be the same (if the sequence contains duplicate numbers).

There must be at least 2 (two) numbers in the list of numbers that is not the terminating value. If the user enters less than 2 (two) numbers, consider an error. Report the error input via IO.reportBadInput() and RE-ASK the user for the input until it is correctly entered.

Example:

java TwoSmallest 123 [this is the terminating value, not part of the set of numbers] 17.0 23.5 10.0 15.2 30.0 8.0 16.0 123 [this is the terminating value again, indicating that the user is done] RESULTS TO OUTPUT (in this order): 8.0 10.0 

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!