“找不到符号-类扫描器"错误 [英] "cannot find symbol - class Scanner" error

查看:76
本文介绍了“找不到符号-类扫描器"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

public class Workshop3
{
    public static void main (String [] args)
    {
        System.out.println ("please enter radius of circle");
        double radius;
        Scanner keyboard = new Scanner (System.in);
        keyboard.nextDouble (radius);
    }
}

我收到的错误是

找不到符号-类扫描器

cannot find symbol - class scanner

在线

Scanner keyboard = new Scanner (System.in);

推荐答案

由于OP是编程的新手,所以我想解释更多.

As the OP is a new beginner to programming, I would like to explain more.

您需要在代码顶部使用以下行才能进行编译:

You wil need this line on the top of your code in order to compile:

import java.util.Scanner;

这种导入语句非常重要.他们告诉编译器您将要使用哪种类型的扫描仪,因为这里的扫描仪未被任何人定义.

This kind of import statement is very important. They tell the compile of which kind of Scanner you are about to use, because the Scanner here is undefined by anyone.

在导入语句之后,您可以直接使用Scanner类,编译器将对此有所了解.

After a import statement, you can use the class Scanner directly and the compiler will know about it.

此外,尽管我不建议这样做,但您无需使用import语句也可以做到这一点:

Also, you can do this without using the import statement, although I don't recommend:

java.util.Scanner scanner = new java.util.Scanner(System.in);

在这种情况下,您只需直接告诉编译器您要使用的扫描仪即可.

In this case, you just directly tell the compiler about which Scanner you mean to use.

这篇关于“找不到符号-类扫描器"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆