<s>[INST] import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();

    int cout = 0;

    for (int i = 0; i < n; i++) {
      String str = scanner.nextLine();

      if (str.equals("cat")) {
        cout++;
      }
    }

    System.out.println(cout);
  }
}

However, I'm having trouble with the following error:

Exception in thread "main" java.util.NoSuchElementException: No line found

at java.util.Scanner.nextLine(Scanner.java:1587)
at Main.main(Main.java:11)
The error is occurring because of the scanner.nextInt() and scanner.nextLine() combination. What is the best way to get the input from the user?[/INST]