爲什麼我得到一個int數太大,long分配給min和max?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);
}
}
你可以用'Long.MIN_VALUE'和'Long.MAX_VALUE'或'1L << -1'和'-1L >>> 1' –