简体   繁体   English

java netbeans IDE 8.2中的扫描程序导入问题

[英]scanner import problem in java netbeans IDE 8.2

so i thought is there any way that i could import a java class for example a scanner class without actually using the keyword "import" in netbeans IDE 8.2?? 所以我认为有没有办法可以导入一个java类,例如一个扫描仪类而不在netbeans IDE 8.2中实际使用关键字“import”? i tried using the alt-enter way but that didn't work in netbeans. 我尝试使用alt-enter方式,但这在netbeans中不起作用。

I have already tried using the alt-enter way but that didn't work. 我已经尝试过使用alt-enter方式但是没有用。

i tried writing "Scanner scanner = new Scanner(System.in)" between the package name and the public class name and then pressing alt-enter to import the java class but that did not work. 我尝试在软件包名称和公共类名称之间编写“Scanner scanner = new Scanner(System.in)”,然后按alt-enter导入java类但不起作用。 the error kept showing class,interface or enum expected. 错误保持显示类,接口或枚举预期。

Actually yes you can: 实际上是的,你可以:

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

Also it is applicable to every library. 它也适用于每个图书馆。

in Java the import keyword is to avoid ussing the fully quallified name of the class you want to use. 在Java中,import关键字是为了避免使用要使用的类的完全quallified名称。 so if you dont want to use the import statement you can declare your Scanner this way, in the same position as you do it when you are importing: 因此,如果您不想使用import语句,您可以通过这种方式声明您的扫描仪,与导入时的位置相同:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM