Hi. I am working on a program in which the user enters a series of integers, and the program displays the highest and lowest integers after the user inputs -99. My problem is initializing the variables; I have no clue how to make my loop work in all cases, just some. For example if I input the following: 2, 3, 4, and then end with -99, 0 is my lowest number, and 4 is my highest. I know my variables are set to 0, and I have no idea how to fix this. Here's the code, help would be much appreciated.
import java.util.Scanner;
public class largeandsmall {
public static void main(String[] args) {
int smallNumber = 0;
int largeNumber = 0;
int userNumber;
Scanner scan = new Scanner(System.in);
System.out.println("Please enter a series of numbers. Enter " + -99 + " when you " +
"finish entering your numbers.");
do {
userNumber = scan.nextInt();
if (userNumber > largeNumber && userNumber > smallNumber && userNumber != -99)
largeNumber = userNumber;
else if (userNumber < smallNumber && userNumber < largeNumber && userNumber !=-99)
smallNumber = userNumber;
else if (userNumber == -99)
System.out.println("Here are your smallest and largest values entered in order: "
+ smallNumber + " " + largeNumber);
} while (userNumber != -99);
}
}