Enter a series of number then display largest and smallest entered number

I'm required to wite a program which lets the user enter a series of integers.  Th series will continue until the user enters -99.  The program should display the largest and smallest numbers entered.  My program will display the largest number correctly, however, the smallest number displaying is always -99.  Not sure why the smallest number is not printing.  Any feedback will be appreciated.
import javax.swing.JOptionPane;
import java.util.Scanner;
 
 
public class LargestSmallestNumbers
{
	public static void main (String args[])
	{
		int number = 0;
		int largest = 0;
		int smallest = 0;
		
		Scanner keyboard = new Scanner(System.in);
		
		System.out.println("Enter series of number.  Select -99 to end series");
		System.out.println();
		
			while (number != -99)
			{
				
				number = Integer.parseInt(JOptionPane.showInputDialog("Enter integer"));
				
 
					if (number >= largest)
						largest=number;
					else if (number < largest && smallest >= number)
								smallest=number;
					else
								largest = largest;
								smallest = smallest;
			}
 
				System.out.println("Largest number: " + largest);
				System.out.println("Smallest number: " + smallest);
				
	}
}

Open in new window

gkilgoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gkilgoreAuthor Commented:
Any feedback yet.
0
gkilgoreAuthor Commented:
I need to write a program which will allow me to enter a series of integers.  The series will continue until -99 has been entered which will end the series.  Based upon the numbers entered, the program should display the largest and smallest numbers.  The program thus far will display the largest number entered however, the smallest number displayed is always -99.  Which is the number used to end the series.  Not sure what I am missing in my program.  Any suggestions?  Thank you!
0
gkilgoreAuthor Commented:
Please close this program.  No additional assistance is required.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.