MAX_VALUE được dùng để tìm giá trị tối đa có thể cho integer trong Java. Hãy xem ví dụ:
Ví dụ
public class Demo {
public static void main(String[] args) {
System.out.println("The type is");
System.out.println(Integer.TYPE);
System.out.println("The size is");
System.out.println(Integer.SIZE);
System.out.println("The max value of integer is");
System.out.println(Integer.MAX_VALUE);
}
}
Kết quả
The type is int The size is 32 The max value of integer is 2147483647
Một lớp tên Demo sử dụng lớp Integer và đưa ra các đặc điểm của lớp Integer như kiểu, kích thước và max_value. Giá trị tối đa mà integer có thể chứa có thể được tính bằng cách gọi lớp Integer với giá trị MAX_VALUE. Nó được hiển thị trên console.