There are four integer variable types in Java: byte (8 bits), short (16 bits), int (32 bits, default type), long (64 bits). Choosing the appropriate type depends on the size of the number that needs to be stored. To store a smaller range of numbers, use byte or short, and to store a larger range of numbers, use int or long.
Integer variables in Java
Integer variables are variable types used to store integer data in Java , divided into four types:
byte
short
int
long
Choose the appropriate integer type
Different integer types have different value ranges, and choosing the appropriate type depends on the size of the number that needs to be stored. For smaller ranges of numbers, you can use byte or short. For larger ranges of numbers, you can use int or long. For example:<code class="java">byte b = 127; // 8 位,取值范围:-128 至 127 short s = 32767; // 16 位,取值范围:-32768 至 32767 int i = 2147483647; // 32 位,取值范围:-2147483648 至 2147483647 long l = 9223372036854775807L; // 64 位,取值范围:-2^63 至 2^63-1</code>
Note:
The above is the detailed content of What are the integer variables in java. For more information, please follow other related articles on the PHP Chinese website!