I am having a strange problem when trying to submit a class assignment. When I run the program it runs as intended but when uploading it and running the test cases on the code it spits out a java.util.NoSUchElementException error on line 31. I tried putting the code into its own method then calling it to see if it would change anything but it did not :(
The program is supposed to take an input from the user and then output the minimum and maximum values of the values that have been entered.
here is my code so far:
import java.util.Scanner;
public class MaxMin
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a number (-1 to quit): ");
int num = input.nextInt();
minMax(num);
}
public static void minMax(int userInput) {
Scanner input = new Scanner(System.in);
int min = userInput;
int max = userInput;
while(userInput != -1) {
if(userInput < min) {
min = userInput;
}
else if (userInput > max){
max = userInput;
}
System.out.println("Smallest # so far: " + min);
System.out.println("Largest # so far: " + max);
System.out.println("Enter a number (-1 to quit): ");
userInput = input.nextInt();
}
System.out.println("You quit the program.");
}
}
Any help on how to solve this problem would be greatly appreciated.