Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I import a math library, and if so how?

So I want to print out the math functions, "PI" and "E."

Here is how I'm trying to do it:

System.out.println(Math.PI);
System.out.println(Math.E);

I think I have to import the math library.

like image 622
user3314801 Avatar asked Oct 23 '25 17:10

user3314801


2 Answers

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.)

like image 57
T.J. Crowder Avatar answered Oct 26 '25 06:10

T.J. Crowder


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

like image 31
sadhu Avatar answered Oct 26 '25 07:10

sadhu