Math.E, PI. Sometimes programs need to use the E and pi constants. With the Math class, we can access these as fields. We do not need to specify 3.14 for pi.
Tip: Using these included constants results in much clearer code—and no mistakes in the value of pi.
Java program that gets Math.E, PI
public class Program {
public static void main(String[] args) {
// Get these known constants.
double value1 = Math.E;
double value2 = Math.PI;
System.out.println(value1);
System.out.println(value2);
}
}
Output
2.718281828459045
3.141592653589793
No Comment to " Java Program on Math.E, PI. "