could you please help me to make this program to get a correct number? The program should check the input type, it should be int. Also, the program should check that the value is from 1 to 10. If these conditions are true, the value should be assigned to correctNumber. So far I came up to this piece of code but I have difficulties in making it work properly.
System.out.println("Enter a number from 1 to 10:");
Scanner scanner = new Scanner(System.in);
while (!scanner.hasNextInt() || !isCorrectNumber(scanner.nextInt())) {
System.out.println("Incorrect input!");
scanner.next();
}
int correctNumber = scanner.nextInt();
}
private static boolean isCorrectNumber(int n) {
return size >= 1 && size <= 10;
}