java.lang.StrictMath là một final class và là lớp con của Object. Lớp StrictMath chứa các phương thức thực hiện các phép toán số học cơ bản như hàm mũ (exponential), logarit, căn bậc hai và hàm lượng giác. Chúng ta không cần tạo instance cho StrictMath vì tất cả các phương thức trong StrictMath đều là phương thức static. Các phương thức quan trọng bao gồm abs(), acos(), asin(), atan(), ceil(), floor(), log(), max(), min(), pow(), random(), round() v.v.
Cú pháp
public final class StrictMath extends Object
Ví dụ
public class StrictMathTest {
public static void main(String args[]) {
System.out.println("Giá trị tuyệt đối: " + StrictMath.abs(-100.50));
System.out.println("Giá trị ceil: " + StrictMath.ceil(100.55));
System.out.println("Giá trị floor: " + StrictMath.floor(100.55));
System.out.println("Giá trị max: " + StrictMath.max(100, 200));
System.out.println("Giá trị min: " + StrictMath.min(100, 200));
System.out.println("Giá trị random: " + StrictMath.random());
System.out.println("Giá trị round: " + StrictMath.round(100.75));
System.out.println("Giá trị căn bậc hai: " + StrictMath.sqrt(2));
System.out.println("Giá trị PI: " + StrictMath.PI);
System.out.println("Giá trị log: " + StrictMath.log(10.55));
}
}
Kết quả
Giá trị tuyệt đối: 100.5 Giá trị ceil: 101.0 Giá trị floor: 100.0 Giá trị max: 200 Giá trị min: 100 Giá trị random: 0.22227639516105102 Giá trị round: 101 Giá trị căn bậc hai: 1.4142135623730951 Giá trị PI: 3.141592653589793 Giá trị log: 2.3561258599220753