Dhruv Tyagi
Dhruv Tyagi

Reputation: 11

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?? i tried using the alt-enter way but that didn't work in netbeans.

I have already tried using the alt-enter way but that didn't work.

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. the error kept showing class,interface or enum expected.

Upvotes: 1

Views: 1096

Answers (2)

Daniel_Kamel
Daniel_Kamel

Reputation: 619

Actually yes you can:

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

Also it is applicable to every library.

Upvotes: 2

Soni Sol
Soni Sol

Reputation: 2612

in Java the import keyword is to avoid ussing the fully quallified name of the class you want to use. 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:

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

Upvotes: 1

Related Questions