Finding 'highest' & 'lowest'
I know how to find the highest and lowest of a predetermined amount of values, but I'm confused on how to do it with an indefinite amount. I know you can use arrays... but we haven't gone over those yet, so there has to be another method. Here's the simple program I wrote to enter in an indefinite amount of ages:
import java.util.*;
publicclass Ages348
{
publicstaticvoid main(String[] args)
{
/*** Below is my identification of all the identifiers (or variables)
that I will be using in the following code.***/
int ages =0;
int totalAgesAverage = 0;
int totalAgesSum = 0;
int agesInput;
Scanner scannerObject =new Scanner(System.in);
System.out.println("This program will allow you to enter in the age, in years,");
System.out.println("of an indefinite amount of people. It will then output the ");
System.out.println("number of ages that you entered, the sum of those ages, the");
System.out.println("average age entered, as well as the highest and lowest age.\n");
System.out.println("Enter -1 when you are done entering ages.\n");
System.out.println("\nEnter your ages here:");
agesInput = scannerObject.nextInt();
/***This loop is created so the user can continue to enter as mnay ages as they would like.
when they are finished, they will enter "-1" and the loop will terminate ****/
while (agesInput!= -1)/*While loop to enter. Enter -1 to exit */
{
totalAgesSum += agesInput;/*Sums all the ages entered.*/
ages ++;/* Counts the number of ages entered */
agesInput = scannerObject.nextInt();
}/*End of while loop.*/
System.out.println("\n");
totalAgesAverage = totalAgesSum / ages;/*Calculates average age.*/
/*This is where all the information is output to the DOS prompt./
System.out.println("You have entered a TOTAL of " + ages + " ages");
System.out.println("The SUM of all ages antered is: "+totalAgesSum+"");
System.out.println("The AVERAGE age is: "+totalAgesAverage+"");
System.out.println("\n\n");
}/*End of main method.*/
}/*End of class Ages348.*/
I can get the total, sum and average... but can someone point me in the right direction as to how I would find the highest and lowest numbers entered by the user?
Thanks in advance for the assistance...

