Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The problem I have is that I don\'t know how to create code that will output the

ID: 3787552 • Letter: T

Question

The problem I have is that I don't know how to create code that will output the user's smallest and second smallest number. Here is my code so far: help?

public static void smallest2(Scanner console) {
    while(true)
{
int count = 0;
int n = 0;
int i =0;
   
System.out.print("number? ");
n = console.nextInt();
i++;
if(n%2 == 0) {
    //boolean m = (i < 0);
    System.out.print("smallest: " + );
    n = console.nextInt();
    System.out.print("second smallest: "+ n);
    n = console.nextInt();
}}}

(THE QUESTION PROBLEM:)

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.

Call smallest2(console); smallest2(console); smallest2(console); smallest2(console); Output
  number? 8  number? 10  number? 2  number? 1  number? 22  number? -1  smallest: 1  second smallest: 2                    
  number? 5  number? 6  number? 7  number? 8  number? 9  number? -5  smallest: 5  second smallest: 6                    
  number? 5  number? 5  number? 5  number? 5  number? -3  smallest: 5  second smallest: 5                    
  number? 200  number? 100  number? -103  smallest: 100  second smallest: 200                    

Explanation / Answer

import java.utill.Scanner;

public clssABC {

public static void main(string[]args) {

int num;

Scanner scanner = nwe Scanner(System.in);

System.out.println("feed me with numbers:");

while((num=scanner.nextInt())>0) {

System.out.println("keepgoing!");

}

{

system.out.println("number is negative! System Shutdown!");

}

}

}

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote