Use the shortcut ctrl+shft+o in Eclipse. It automatically imports whatever classes needed and suggests you with possible imports if conflict occurs.
Answer from Vanaja Jayaraman on Stack Overfloweclipse - the import java.util.scanner cannot be resolved - Stack Overflow
Java scanner not working on eclipse - Stack Overflow
methods - Can't import java.util.Scanner - Stack Overflow
Java "import.java.util.Scanner" Error on Eclipse IDE - Stack Overflow
Scanner is a Java class. All classes in Java should start with a capital letter.
Change
java.util.scanner;
to
java.util.Scanner;
either import the class or import the whole package
Importing class
import java.util.Scanner;
2.Importing the whole package
`import java.util.*;`
First will import only the selected class and the second will import all the classes in the package.
I guess you are using an IDE (like Netbeans or eclipse) which allows you to run the code even if certain classes are not compilable. During the application's runtime, if you access this class it would lead to this exception.
Solution :- Simply Clean Your Project and Build and Run Then Again.
Make sure you have configured PATH, CLASSPATH and JAVA_HOME variable in system Environment variable.
1) It might refers older version of java then 1.5
or
2) May be not added PATH,CLASSPATH, JAVA_HOME variable there.
BTW Your code is works fine in my Eclipse.
