Scanner number = new Scanner(System.in); int a = Integer.MAX_VALUE; int b = Integer.MAX_VALUE; int c = number.nextInt(); while (number.hasNextInt()) {if (c < a) {a = c;} else if ((c < b) && (c!=a)) {b = c;} c = number.nextInt();} System.out.println(b);