• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 908
  • Last Modified:

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");
			while (number != -99)
				number = Integer.parseInt(JOptionPane.showInputDialog("Enter integer"));
					if (number >= largest)
					else if (number < largest && smallest >= number)
								largest = largest;
								smallest = smallest;
				System.out.println("Largest number: " + largest);
				System.out.println("Smallest number: " + smallest);

Open in new window

  • 3
1 Solution
gkilgoreAuthor Commented:
Any feedback yet.
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!
gkilgoreAuthor Commented:
Please close this program.  No additional assistance is required.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now