xxxxxxxxxx
public class OutputFormattingExample {
public static void main(String[] args) {
int myInt = 42;
double myDouble = 3.14159;
String myString = "Hello";
System.out.printf("Integer: %d\n", myInt);
System.out.printf("Double: %.2f\n", myDouble);
System.out.printf("String: %s\n", myString);
}
}
xxxxxxxxxx
// Here is an example from https://docs.oracle.com/javase/tutorial/java/data/numberformat.html
System.out.format("The value of " + "the float variable is " +
"%f, while the value of the " + "integer variable is %d, " +
"and the string is %s", floatVar, intVar, stringVar);