Home  >  Article  >  Java  >  What is the purpose of StrictMath class in Java?

What is the purpose of StrictMath class in Java?

PHPz
PHPzforward
2023-09-12 21:21:021371browse

What is the purpose of StrictMath class in Java?

java.lang.StrictMath is a final class that is a subclass of the Object class. The StrictMath class contains methods for performing basic numerical operations, such as elementary exponents, logarithms, square roots, and trigonometric functions. We don't need to create an instance for the StrictMath class because all methods in the StrictMath class are static methods. The important methods of the StrictMath class are abs(), acos(), asin(), atan(), ceil(), floor(), log(), max(), min(), pow(), random(), round() etcSyntax

public final class StrictMath extends Object
Example

public class StrictMathTest {
   public static void main(String args[]) {
      System.out.println("Absolute Value: " + StrictMath.abs(-100.50));
      System.out.println("Ceil Value : " + StrictMath.ceil(100.55));
      System.out.println("Floor Value : " + StrictMath.floor(100.55));
      System.out.println("Maximum Value : " + StrictMath.max(100,200));
      System.out.println("Minimum Value : " + StrictMath.min(100,200));
      System.out.println("Random Value : " + StrictMath.random());
      System.out.println("Round Value: " + StrictMath.round(100.75));
      System.out.println("Square Root Value : " + StrictMath.sqrt(2));
      System.out.println("PI Value: " + StrictMath.PI);
      System.out.println("Log Value: " + StrictMath.log(10.55));
   }
}

Output

Absolute Value: 100.5
Ceil Value : 101.0
Floor Value : 100.0
Maximum Value : 200
Minimum Value : 100
Random Value : 0.22227639516105102
Round Value: 101
Square Root Value : 1.4142135623730951
PI Value: 3.141592653589793
Log Value: 2.3561258599220753

The above is the detailed content of What is the purpose of StrictMath class in Java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete