String.format and Text Blocks
String.format and printf use %s, %d, %.2f. Text blocks use triple quotes.
Example
public class Main {
public static void main(String[] args) {
System.out.printf("%s is %d and %.1f%n", "Ada", 30, 1.68);
String tb = """
line one
line two
""";
System.out.print(tb);
}
}Result
Ada is 30 and 1.7 line one line two
Exercise
Format decimals.
"%.f"
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.