Java – compile errors using scanner

This is my current course:

package Mathias;

import java.util.*;

public class Scanner {
    public static void main(String args[]) {
        System.out.print("What's your name?");
        Scanner sc = new Scanner(system.in);
        String Input = sc.nextLine();
        System.out.println("Hello," + Input + ".");
    }
}

I encountered two errors in the 5th and 5th, line 6 Error 1 http://puu.sh/64VGk.jpg

Error 2 http://puu.sh/64VHe.jpg

Solution

You need to name your course other than scanner The name is already used by Java util. Scanner uses, and creating a new class with that name can confuse the compiler

Alternatively, you can try to specify:

java.util.Scanner sc = new java.util.Scanner(system.in);

So your code is clear

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>