import java.util.Scanner;
public class JavaApplication75 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = -2, largest = -1, smallest = -1;
while (true){
System.out.println("Enter a number (-1 to quit):");
num = scan.nextInt();
while (num < 0){
if (num == -1){
System.exit(0);
}
num = scan.nextInt();
}
if (num > largest){
largest = num;
}
if (num < smallest || smallest == -1){
smallest = num;
}
System.out.println("Smallest # so far: "+smallest);
System.out.println("Largest # so far: "+largest);
}
}
}
I hope this helps!