Question: Write a static method named smallest2 that accepts a Scanner for console input as a parameter. The method repeatedly prompts the user for a

Write a static method named smallest2 that accepts a Scanner for console 

Write a static method named smallest2 that accepts a Scanner for console input as a parameter. The method repeatedly prompts the user for a sequence of integers until the user enters a negative number. The method then prints the smallest two nonnegative numbers entered by the user. (You may assume the user will enter at least 2 nonnegative numbers.) Notice you do not have to print the two smallest unique numbers entered by the user. For example, if the user enters 2, 2, and 3, the two smallest numbers entered are 2 and 2. Example Output: Call smallest2(console); smallest2(console); smallest2(console); smallest2(console); Output number? 8 number? 5 number? 5 number? 200 number? 10 number? 6 number? 2 number? 7 number? 1 number? 8 number? 22 number? -1 smallest: 1 second smallest: 2 number? 9 number? -5 smallest: 5 second smallest: 6 number? 5 number? -3 smallest: 5 second smallest: 5 number? 100 number? -103 smallest: 100 second smallest: 200 number? 5 number? 5

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 Programming Questions!