E and PI are not functions, they're static fields (data members). That code will output their values correctly. You don't have to import anything, the Math class is in the java.lang package, which is imported by default. (It's the only package imported by default, I believe.)
E and PI are not functions, they're static fields (data members). That code will output their values correctly. You don't have to import anything, the Math class is in the java.lang package, which is imported by default. (It's the only package imported by default, I believe.)
You don't have to import anything here. The java.lang.Math class should already be available as java.lang package is imported by default
[Java] The import java.util.Math cannot be resolved
How do I use/import the Apache Commons Math Java library?
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.comIn Java, you cannot import single methods from a class, so how would I do it in my language?
Videos
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?