Hello, the following question arose: a number is entered from the keyboard if it is an integer, then some code will be executed, if not, a line is output that the number is not an integer and a new one is entered. There is a code:
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Введите кол-во интервалов: "); if (!sc.hasNextInt()) { while (sc.hasNextInt() == false){System.out.println("Некорректный тип введеного числа! Повторите попытку: ");} } else { int n = sc.nextInt(); } } } If I enter a whole everything is normal, when entering for example 2.3, an infinite loop works and I cannot enter a number. The question is trivial, but tell me, please, what is wrong.