I tried to optimize solution by handling user input exceptions.
public class Solution {
private static Integer TERMINATION_VALUE = 0;
public static void main(String[] args) {
Integer value = null;
Integer minimum = Integer.MAX_VALUE;
Integer maximum = Integer.MIN_VALUE;
Scanner scanner = new Scanner(System.in);
while (value != TERMINATION_VALUE) {
Boolean inputValid = Boolean.TRUE;
try {
System.out.print("Enter a value: ");
value = scanner.nextInt();
} catch (InputMismatchException e) {
System.out.println("Value must be greater or equal to " + Integer.MIN_VALUE + " and less or equals to " + Integer.MAX_VALUE );
inputValid = Boolean.FALSE;
scanner.next();
}
if(Boolean.TRUE.equals(inputValid)){
minimum = Math.min(minimum, value);
maximum = Math.max(maximum, value);
}
}
if(TERMINATION_VALUE.equals(minimum) || TERMINATION_VALUE.equals(maximum)){
System.out.println("There is not any valid input.");
} else{
System.out.println("Minimum: " + minimum);
System.out.println("Maximum: " + maximum);
}
scanner.close();
}
}