29.4. Printing Integers
An integer is a whole number, such as 776, 0 or –52, that contains no decimal point. Integer values are displayed in one of several formats. Figure 29.1 describes the integral conversion characters.
Conversion character | Description |
---|---|
d | Display a decimal (base 10) integer. |
o | Display an octal (base 8) integer. |
x or X | Display a hexadecimal (base 16) integer. X causes the digits 0–9 and the letters A–F to be displayed and x causes the digits 0–9 and a–f to be displayed. |
Figure 29.2 prints an integer using each of the integral conversions. In lines 9–10, note that the plus sign is not displayed by default, but the minus sign is. Later in this chapter (Fig. 29.14) we will see how to force plus ...
Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.