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.