Concept Flow - Output formatting basics
Start Program
Prepare Output Data
Choose Format Specifier
Apply Formatting
Print Formatted Output
End Program
The program prepares data, chooses how to format it, applies formatting, then prints the result.
int age = 25; String name = "Anna"; System.out.printf("Name: %s, Age: %d\n", name, age);
| Step | Action | Format Specifier | Values Used | Output Produced |
|---|---|---|---|---|
| 1 | Declare int age | - | - | No output |
| 2 | Declare String name | - | - | No output |
| 3 | Call printf with format | "Name: %s, Age: %d\n" | name="Anna", age=25 | Name: Anna, Age: 25 |
| 4 | Program ends | - | - | Output complete |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| age | undefined | 25 | 25 | 25 |
| name | undefined | "Anna" | "Anna" | "Anna" |
Use System.out.printf to print formatted output.
Placeholders like %s for strings and %d for integers.
Variables fill placeholders in order.
Ends with \n for new line.
Example: printf("Name: %s, Age: %d\n", name, age);