Scanner is a Java class. All classes in Java should start with a capital letter.
Change
java.util.scanner;
to
java.util.Scanner;
Answer from David.Jones on Stack OverflowScanner 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.
eclipse - how to import java.util.Scanner - Stack Overflow
java.util.Scanner cannot be resolved - Stack Overflow
methods - Can't import java.util.Scanner - Stack Overflow
java - Scanner cannot be resolved to a type - Stack Overflow
You need to also import the class itself. At the very top of the file, above public class student, you need to add:
import java.util.Scanner;
In addition, I'd like to pose a few more possible corrections:
- Class names should be
PascalCase - Your code should have consistent indentation. Ctrl+Shift+F is your friend here.
Just use import java.util.Scanner; or use import java.util.*;
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.
The Scanner class is new in Java 5. I do not know what Hardy's default Java environment is, but it is not Sun's and therefore may be outdated.
I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.
If you are using a version of Java before 1.5, java.util.Scanner doesn't exist.
Which version of the JDK is your Eclipse project set up to use?
Have a look at Project, Properties, Java Build Path -- look for the 'JRE System Library' entry, which should have a version number next to it.
in is not assigned to anything. You would have to close your scanner called Input.
try{
// code
}
catch(Exception ex)
{
// Exception handling
}
finally{
if(Input!=null){
Input.close();
}
}
Your variable name is Input and you are trying to do in.close().
It should be:
finally {
Input.close();
}
I tested if Java was running in command prompt and it said it was and i installed the extensions yet it still doesnt work, what am i doing wrong
I'm writing a program to calculate the wind chill based on a temperature and wind speed entered by the user. The formula to calculate wind chill is
Wind Chill = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16
My current code is
import java.util.Scanner;
import java.util.Math;
public class WindChill {
public static void main(String[] args) {
//Declare variables
double windChill;
double temperature;
int windSpeed;
//Ask the user for temperature and wind speed
System.out.print("Enter the temperature (Fahrenheit): ");
Scanner input = new Scanner (System.in);
temperature = input.nextDouble();
System.out.print("Enter the wind speed(mph): ");
windSpeed = input.nextInt();
//Display the wind chill value
windChill = (35.74+(0.6215*temperature)) - (Math.pow(35.75*windSpeed,0.16)) + (Math.pow(0.4275*temperature*windSpeed,0.16));
System.out.print("The wind chill index is " + windChill);
}}
I get an error in the IDE on line 2 that says "the import java.util.Math could not be resolved". Also, when I try to run the program, I get the error message
"Exception in thread "main" java.lang.Error: Unresolved compilation problem: at WindChill.main(WindChill.java:6)
I checked my installed JREs and I am using JRE7. Can anybody tell me what is wrong?