Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java Programming

Authors: Joyce Farrell

9th edition

1337397075, 978-1337397070

More Books

Students also viewed these Programming questions

Question

What are the parameters in a simple linear regression model?

Answered: 1 week ago

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

What is the signicance of play for development?

Answered: 1 week ago

Question

How does play change as a child is growingup?

Answered: 1 week ago