Sentinel-controlled while loop processing issue
I am to create a program allowing the user to enter in integers, the program will display all integers entered and the maximum and minimum of those integers. The user ends the program by entering -999.
Problem: When the user enters -999 it is recorded as the minimum integers they entered when it should just stop the loop and display the output without itself being displayed. What do I have wrong in my code? Any help you can give me will be very appreciated, thank you.
import javax.swing.JOptionPane;
public class MaxMinOfIntegers
{
public static void main ( String [] args )
{
//preparations
String outputMessage, instructions, openingMessage, listOfNumbers = " ";
String closingMessage;
int number, max = 0, min = 0, numberOfIntegers = 0;
openingMessage = "This program allows a user to enter in numbers, it will keep " +
"track of numbers entered along with the maximum and minimum. \n\n";
instructions= "Please enter a number or enter -999 to quit and view the results. \n";
closingMessage = "End of program, have a nice day. ";
//input
JOptionPane.showMessageDialog ( null, openingMessage );
number = Integer.parseInt ( JOptionPane.showInputDialog ( null, instructions ) );
//processing
while ( number != -999 )
{
number = Integer.parseInt ( JOptionPane.showInputDialog ( null, instructions ) );
listOfNumbers += number + " " ;
if ( number > max )
max = number;
if ( number < min )
min = number;
}
//output
if ( numberOfIntegers == 0 )
outputMessage = "End of program, thank you.";
else
outputMessage = "The numbers you have entered are " + listOfNumbers +
", the maximum number is " + max +
" and the minimum number is " + min + ". \n End of program, thank you.";
JOptionPane.showMessageDialog ( null, outputMessage );
System.exit (0);
//end main method
}
//end class
}

