← Java from Scratch
Lesson 2 of 88 · 10 XP
Output
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
System.out.println(x)— prints and moves to a new line;System.out.print(x)— without a line break;System.out.printf(format, ...)— formatted output, as in C.
System.out.print("Score: ");
System.out.println(2 + 3); // Score: 5
System.out.println("2 + 3 = " + 2 + 3); // 2 + 3 = 23 — string + number is joined from left to right!
System.out.println("2 + 3 = " + (2 + 3)); // 2 + 3 = 5
System.out.printf("%s: %d points, %.1f%%%n", "Kai", 42, 97.5); // Kai: 42 points, 97.5%
%d — an integer, %s — a string, %.2f — a fractional number with 2 decimal places, %n — a line break, %% — the percent sign itself.
In strings: \n is a line break, \t a tab, \" a quote.
Task. Print three lines:
IGD Games
2 + 3 = 5
"Java"
Get the five with an expression, not as text.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.