Topic 6_Math Class in Java
Topic 6_Math Class in Java
Output:
The value of PI: 3.141592653589793
Example 2: Finding the Maximum Number
The Math class provides a method called max() that returns the greater of two
values. You can use this method without importing the Math class. Here's an
example:
int num1 = 40;
int num2 = 87;
System.out.println("The maximum number: " + Math.max(num1, num2));
Output:
The maximum number: 87
Output:
The square root of 100 is: 10.0
int number = 2;
System.out.println("The power of 3 is: " + Math.pow(number, 3));
Output:
The square root of 100 is: 10.0
Output:
The value of PI: 3.141592653589793
The maximum number: 87
The square root of 100 is: 10.0
Output:
The area of the circle is: 78.53981633974483
double base = 2;
double exponent = 3;
double result = exp(exponent * log(base));
}
}
Output:
The exponential value is: 8.0
doube angle = PI / 4;
double sine = sin(angle);
double cosine = cos(angle);
double tangent = tan(angle);
Output:
Sine: 0.7071067811865475
Cosine: 0.7071067811865476
Tangent: 0.9999999999999999
Method Description
Math.pow() It returns the value of first argument raised to the power to second
argument.
Math.ceil() It is used to find the smallest integer value that is greater than or equal
to the argument or mathematical integer.
Math.copySign() It is used to find the Absolute value of first argument along with sign
specified in second argument.
Math.floor() It is used to find the largest integer value which is less than or equal to
the argument and is equal to the mathematical integer of a double
value.
Math.floorDiv() It is used to find the largest integer value that is less than or equal to
the algebraic quotient.
Math.random() It returns a double value with a positive sign, greater than or equal
to 0.0 and less than 1.0.
Math.rint() It returns the double value that is closest to the given argument and
equal to mathematical integer.
Math.toIntExact() It returns the value of the long argument, throwing an exception if the
value overflows an int.
Method Description
Math.log1p() It returns the natural logarithm of the sum of the argument and 1.
Math.exp() It returns E raised to the power of a double value, where E is Euler's number and
it is approximately equal to 2.71828.
Math.expm1() It is used to calculate the power of E and subtract one from it.
Method Description
Math.sin() It is used to return the trigonometric Sine value of a Given double value.
Math.cos() It is used to return the trigonometric Cosine value of a Given double value.
Math.tan() It is used to return the trigonometric Tangent value of a Given double value.
Math.asin() It is used to return the trigonometric Arc Sine value of a Given double value
Math.acos() It is used to return the trigonometric Arc Cosine value of a Given double value.
Math.atan() It is used to return the trigonometric Arc Tangent value of a Given double value
Method Description
Math.sinh() It is used to return the trigonometric Hyperbolic Cosine value of a Given double
value.
Math.cosh() It is used to return the trigonometric Hyperbolic Sine value of a Given double value.
Math.tanh() It is used to return the trigonometric Hyperbolic Tangent value of a Given double
value.