I am trying to validate that the user only enters an integer. Is there another way to do this that will make the validation more simplified?
Scanner in = new Scanner(System.in);
System.out.print("Enter the amount of subjects that you need to get an average of: ");
int amount_of_subjects;
    
while (!in.hasNextInt())
{
  // warning statement
  System.out.println("Please Enter integer!");
  in.nextLine();
}
 
amount_of_subjects = Integer.parseInt(in.nextLine());
 
     
     
    