Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Largest and Smallest

807599Nov 16 2006 — edited Nov 17 2006
I am supposed to write a program that asks the user to input a series of numbers. The user should enter -99 to end the program. After typing in -99 the program will tell the user what the highest number and the lowest number was after typing in the series of numbers.

import java.util.Scanner;    // Needed for the Scanner class

public class LargestAndSmallest
{
   public static void main(String[] args)
   {
      int number;                         
      int max;
      int min; 
      
       
      // Create a Scanner object for keyboard input.
      Scanner keyboard = new Scanner(System.in);
      
      // Display general instructions.
      System.out.println("Enter a series of numbers.");
      System.out.println("When you are finished, Enter -99 to end the program.");
      System.out.println();

      // Get the first number of points.
      System.out.print("Enter a value: ");
      number = keyboard.nextInt();     

      // Accumulate the points until -99 is entered.
      while (number != -99)
      {
 
       // Get the next number of points.
         System.out.print("Enter a value: ");
         number = keyboard.nextInt();     
      }
		//not sure what should go here :*(


	  System.out.println("Smallest number: " + min);
	  System.out.println("Largest number: " + max);
      
   }
}
I am unsure of how to find the minimum and maximum number inputted. If someone could give me some insight and point me in the right direction, I would be very appreciative.

Message was edited by:
wksmdt
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 15 2006
Added on Nov 16 2006
26 comments
238 views