~/ learn/ comp-308/ cards/ String.format / printf & escape sequences
1 of 6

Type a formatted log line with width and precision

Type a formatted log line with width and precision

Answer

String line = String.format("[%-8s] temp=%6.2f%n", "SENSOR", 21.5);

%-8s left-justifies the label in an 8-wide field; %6.2f renders 21.5 as " 21.50" (6 wide, 2 decimals); %n is a portable newline. String.format returns the text instead of printing it.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF