To this point, you have learned about the numeric primitive types int, double, and float. You have learned about the basic arithmetic operators, the increment/decrement operators for int, and compound assignment. Other Integer TypesYou have been using the int type for integer numerics. There are other integer types available, each representing different sizes available in which to store numbers of that type. Table 10.1 lists all integral types, their size, and the range of values that they support.
The char type is also a numeric type. Refer to Lesson 3 for more information on char. You usually express numeric literals as decimal, or base 10, numbers. Java also allows you to represent them in hexadecimal (base 16) or octal (base 8). You prefix hexadecimal literals with 0x. assertEquals(12, 0xC); You prefix octal literals with 0: assertEquals(10, 012); Integral literals are by default of int type. You can force an integral literal to be a long by suffixing it with the letter L. The lowercase letter l can also be used, but prefer use of an uppercase L, since the lowercase letter is difficult to discern from the number 1. |