Solved

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

Posted on 2009-07-06
3
871 Views
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.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

0
Comment
Question by:gkilgore
  • 3
3 Comments
 

Author Comment

by:gkilgore
Comment Utility
Any feedback yet.
0
 

Author Comment

by:gkilgore
Comment Utility
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
 

Accepted Solution

by:
gkilgore earned 0 total points
Comment Utility
Please close this program.  No additional assistance is required.  
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
map interface methods 3 52
scores100 challenge 3 82
Modeling a class in java 5 31
eclipse java  build path 6 18
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now