Getting TLE with scanner.nextInt()

Hi,
I’m a beginner on codechef, I’m was solving CodeChef: Practical coding for everyone problem the other day, and I was getting TLE when I tried to take input from scanner nextInt method.

To summarise :

Scanner in = new Scanner(System.in);
int n = in.nextInt(); // this gave TLE for some cases
int n = Integer.parseInt(in.next()); // this worked for some reason