i have to create a loop, in the loop i have to take the input values (from keyboard) and then output min/max and average of the values entered. I have no problem with the average, but the only way i can find how to figure the min/max is through a text file example, which doesnt help me when it has to be through keyboard. help pls
8)
Name:
Anonymous2007-04-04 4:44 ID:WvfTfg+6
import java.util.*;
public class Driver {
public static void main (String[] args) {
int iMin = Integer.MAX_VALUE, iMax = Integer.MIN_VALUE, iInput, iNum = 0, iTotal = 0;
boolean quit = false;
Scanner scan = new Scanner(System.in);
do {
try {
System.out.println("Enter an integer");
iInput = scan.nextInt();
iNum++;
iTotal += iInput;
if (iInput < iMin)
iMin = iInput;
if (iInput > iMax)
iMax = iInput;
}
catch (Exception InputMismatchException) {
while (scan.hasNext())
scan.next(); // flushes the shitty bad info
System.out.println("Not an integer\nDid you want to stop (y/n)?");
quit = scan.nextLine().toLowerCase().charAt(0) == 'y';
}
} while (!quit);
if (iNum != 0) // divide by zero, lulz
System.out.println("Min: " + iMin + "\nMax: " + iMax + "\nAverage: " + (double)iTotal / iNum);
while (true)
System.out.println("I love gay porn");
}
}