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

Posted on 2009-07-06
Last Modified: 2013-11-24
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.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

Question by:gkilgore
  • 3

Author Comment

ID: 24791020
Any feedback yet.

Author Comment

ID: 24809077
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!

Accepted Solution

gkilgore earned 0 total points
ID: 24850608
Please close this program.  No additional assistance is required.  

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 134
JUnit 4 @Before and @BeforeClass differences 3 71
github account with ecipse 1 53
eclipse argument 14 69
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question