Объясните, что я делаю нет так, и как лучше поступить
import java.util.Scanner;
/*
Второе минимальное число из введенных
*/
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int cont1 = Integer.MAX_VALUE, cont2 = cont1, x;
while (scanner.hasNextInt()) {
x = scanner.nextInt();
if (x < cont1){
cont2=cont1;
cont1 = x;
}
if(x>cont1 && x<cont2){
cont2 = x;
}
}
System.out.println(cont2);
}
}