Formatting Output
A free lesson from Swipe Coding · Java, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
Now you will combine everything you have learned so far — println(), print(), and the escape characters \n, \t, and \" — to format output exactly the way you want it.
System.out.println("=== Shopping List ===");
System.out.println("Apples");
System.out.println("Bread");
System.out.println("Milk");
// Output:
// === Shopping List ===
// Apples
// Bread
// MilkThe same output can also be produced with just a single println() call if you use \n to separate the lines within the text.
System.out.println("=== Shopping List ===\nApples\nBread\nMilk");
// Output:
// === Shopping List ===
// Apples
// Bread
// MilkSystem.out.println("A\nB"); produces the same output as two separate calls, System.out.println("A"); and System.out.println("B");.
With \t you can make multiple lines look like a small table by aligning text into columns.
System.out.println("Product\tPrice");
System.out.println("Apple\t€0.50");
System.out.println("Bread\t€2.00");
// Output:
// Product Price
// Apple €0.50
// Bread €2.00Why do you use \t in multiple consecutive println() lines?
You can also combine print() and println() to build a line out of multiple parts — for example a label, immediately followed by a quote in quotation marks.
System.out.print("Quote: ");
System.out.println("\"Talk is cheap. Show me the code.\"");
// Output:
// Quote: "Talk is cheap. Show me the code."In the example above, ____ is used so that "Quote: " and the quote appear on the same line.
What does this code output?
System.out.print("Result:\t");
System.out.println("42");Output
10 questions · pass with 60% — just like in the app.
What happens automatically after System.out.println("Hi"); outputs the text?
System.out.print() automatically adds a line break at the end.
The escape character ____ produces a line break in the middle of the text.
What does this code output?
System.out.print("A ");
System.out.println("test");\t produces a tab that helps align text into columns.
To output a quotation mark directly in the text, you write ____.
Why do you have to write \\ to output a single backslash?
System.out.println("A\nB"); produces the same output as two separate println() calls for "A" and "B".
What does this code output?
System.out.println("X");
System.out.println("Y");With System.out.____(), the cursor stays on the same line after the output.
Keep your streak going in Swipe Coding
Swipe through every level of Java on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.
Get the Swipe apps →