“找不到符号 - 类扫描仪”错误
这是我的代码
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);
}
}
我收到的错误是
找不到符号-类扫描仪
在线路上
Scanner keyboard = new Scanner (System.in);
This is my Code
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);
}
}
The error I recieve is
cannot find symbol - class scanner
on the line
Scanner keyboard = new Scanner (System.in);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
由于OP是编程的新手,我想解释更多。
为了编译,您需要在代码顶部添加这一行:
这种导入语句非常重要。它们告诉编译器你将要使用哪种扫描仪,因为这里的扫描仪是任何人都未定义的。
在 import 语句之后,您可以直接使用 Scanner 类,编译器会知道它。
另外,您可以在不使用 import 语句的情况下执行此操作,尽管我不建议:
在这种情况下,您只需直接告诉编译器您打算使用哪个扫描程序。
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:
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.
After a import statement, you can use the class Scanner directly and the compiler will know about it.
Also, you can do this without using the import statement, although I don't recommend:
In this case, you just directly tell the compiler about which Scanner you mean to use.
您必须在代码的第一行导入
java.util.Scanner
。You have to import
java.util.Scanner
at first line in the code.您需要将行
import java.util.Scanner;
包含在源文件中的某个位置,最好是在顶部。You need to include the line
import java.util.Scanner;
in your source file somewhere, preferably at the top.您可以通过导入
java.util.*
包来解决此错误 - 您可以通过将以下代码行添加到程序顶部(与其他import
语句一起)来解决此错误):You can resolve this error by importing the
java.util.*
package - you can do this by adding following line of code to top of your program (with your otherimport
statements):有时,当我们尝试打印用户的字符串时可能会发生这种情况,因此在打印之前我们必须使用
例如:
扫描仪扫描=新扫描仪(System.in);
扫描.nextLine();
// 如果我们在缓冲区中从用户那里输出了整数或其他数据类型,那么 /n (换行)会跳过我们的字符串,因此我们使用这一行来打印我们的字符串 String
s=scan.nextLine() ;
System.out.println(s);
sometimes this can occur during when we try to print string from the user so before we print we have to use
eg:
Scanner scan=new Scanner (System.in);
scan.nextLine();
// if we have output before this string from the user like integer or other dat type in the buffer there is /n (new line) which skip our string so we use this line to print our string
String s=scan.nextLine();
System.out.println(s);
请在代码顶部添加以下行
这应该可以解决问题
Please add the following line on top of your code
This should resolve the issue
在代码的最顶部添加
import java.util.Scanner;
。为我工作。Add
import java.util.Scanner;
at the very top of your code. Worked for me.