Constant E and PI
static double E
- base of the natural logarithms.
static double PI
- pi.
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(Math.E);
System.out.println(Math.PI);
}
}
The output:
2.718281828459045
3.141592653589793
Calculate Circle Area using it's radius
public class Main {
public static void main(String[] args) {
int radius = 5;
double area = Math.PI * radius * radius;
System.out.println("Area of a circle is " + area);
}
}
The output:
Area of a circle is 78.53981633974483
Calculate Circle Perimeter with radius
public class Main {
public static void main(String[] args) {
int radius = 5;
double perimeter = 2 * Math.PI * radius;
System.out.println("Perimeter: " + perimeter);
}
}
Perimeter: 31.41592653589793
Home
Java Book
Essential Classes
Java Book
Essential Classes
Math:
- Math class
- Constant E and PI
- Get the absolute value
- sin, cos, tan: Trigonometric functions
- Cube root and square root
- Ceilling and flooring value
- Copy sign
- Raise the power
- Get exponent
- sqrt(x2 +y2)
- IEEE remainder
- logarithm
- Max, min value
- Next value
- Math Random
- Round to int to double
- Round a value to integer
- value * 2^ scaleFactor
- Get the sign
- Degree to Radian, and Radian to Degree
- Returns the size of an ulp of the argument