Intellij Can't Find Scanner Class [Duplicate]

I am using Intellij IDEA.

Here is my code:

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

        int a = scanner.nextInt();
        System.out.println(a);
}

The problem is that when I run it, it works. But, Intellij cannot find Scanner class. It is underlining with red color.

How to fix this?

4

First you should import the Scanner like this:

import java.util.Scanner;// in the top!

and then try this:

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    System.out.println(a);
}
1

Right click on code editor window and click on run.

1
Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest