Why do I get an int number is too large where the long is assigned to min and max?
/*
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);
}
}
All literal numbers in java are by default
ints, which has range-2147483648to2147483647inclusive.Your literals are outside this range, so to make this compile you need to indicate they’re
longliterals (ie suffix withL):Note that java supports both uppercase
Land lowercasel, but I recommend not using lowercaselbecause it looks like a1:Java Language Specification for the same