Tại sao tôi nhận được số int quá lớn, trong đó thời lượng dài được gán cho phút và tối đa?Số lỗi dài quá lớn Java?
/*
long: The long data type is a 64-bit signed two's complement integer.
It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
Use this data type when you need a range of values wider than those provided by int.
*/
package Literals;
public class Literal_Long {
public static void main(String[] args) {
long a = 1;
long b = 2;
long min = -9223372036854775808;
long max = 9223372036854775807;//Inclusive
System.out.println(a);
System.out.println(b);
System.out.println(a + b);
System.out.println(min);
System.out.println(max);
}
}
Bạn có thể sử dụng 'Long.MIN_VALUE' và 'Long.MAX_VALUE' hoặc' 1L << -1' và' -1L >>> 1' –