G.6 Printing Strings and Characters
The c
and s
conversion characters print individual characters and strings, respectively. Conversion characters c and C require a char
argument. Conversion characters s and S can take a String
or any Object
as an argument. When conversion characters C
and S
are used, the output is displayed in uppercase letters. Figure G.5 displays characters, strings and objects with conversion characters c
and s
. Autoboxing occurs at line 9 when an int
constant is assigned to an Integer
object. Line 15 outputs an Integer
argument with the conversion character s
, which implicitly invokes the toString
method to get the integer value. You can also output an Integer
object using the %d
format specifier. In this case, the
Get Java How to Program (early objects), 9/e 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.