[Java] The import java.util.Math cannot be resolved
How come I didn't need to import java.lang.Math for my code?
java.lang is always imported by default for Java.
More on reddit.comI'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?
I had this line of code:
int generator = 1 + (int) (Math.random() * 19);
http://puu.sh/sGVps/b318650d6b.png
The program I create works perfectly but i was wondering why I didn't need to import lang.math despite using random.