changed hardcoded values to variables
replaced hasNextInt with try-catch blocks