Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started