{"id":"printing-print-and-println","slug":"print-and-println","title":"print and println","text":"`System.out.println` prints its text and then ends the line, so the next output starts on a new line. Its sibling `System.out.print` prints the text and stays on the same line, so the next output continues right after it.\n\n```java\nSystem.out.print(\"Loading\");\nSystem.out.print(\"...\");\nSystem.out.println(\" done\");\nSystem.out.println(\"Next line\");\n```\n\n```output\nLoading... done\nNext line\n```\n\n`print` never adds a space by itself. The space before `done` is there because it is inside the quotes.\n\n### An empty line\n\n`System.out.println()` with nothing between the parentheses prints nothing and ends the line. That gives an empty line, or finishes a line that `print` started.\n\n```java\nSystem.out.println(\"First paragraph.\");\nSystem.out.println();\nSystem.out.println(\"Second paragraph.\");\n```\n\n```output\nFirst paragraph.\n\nSecond paragraph.\n```\n","task":"Choose `print` or `println` for the two blanks so the program prints exactly:\n\n```\nCompiling... done!\nRunning.\n```\n","kind":"fill","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.[[print]](\"Compiling... \");\n        System.out.[[println]](\"done!\");\n        System.out.println(\"Running.\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.print(\"Compiling... \");\n        System.out.println(\"done!\");\n        System.out.println(\"Running.\");\n    }\n}\n","hints":["`Compiling... ` and `done!` are on the same line, so the first call must not end the line.","The second call has to end the line, or `Running.` would continue right after `done!`."],"tests":[{"name":"Output","stdin":"","expect":"Compiling... done!\nRunning.","hidden":false}],"require":[],"forbid":[],"more":[{"task":"The text has two paragraphs, but they run together. Add an empty line between them, using `System.out.println()` with nothing inside the parentheses. The output should be:\n\n```\nStep one: write the code.\nStep two: press Check.\n\nIf a test fails, read the message,\nfix the code and press Check again.\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Step one: write the code.\");\n        System.out.println(\"Step two: press Check.\");\n        System.out.println(\"If a test fails, read the message,\");\n        System.out.println(\"fix the code and press Check again.\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Step one: write the code.\");\n        System.out.println(\"Step two: press Check.\");\n        System.out.println();\n        System.out.println(\"If a test fails, read the message,\");\n        System.out.println(\"fix the code and press Check again.\");\n    }\n}\n","hints":["The empty line goes between `Step two: press Check.` and `If a test fails, read the message,`.","Add a new statement `System.out.println();` in that spot."],"tests":[{"name":"Output","stdin":"","expect":"Step one: write the code.\nStep two: press Check.\n\nIf a test fails, read the message,\nfix the code and press Check again.","hidden":false}],"require":[{"pattern":"System\\.out\\.println\\s*\\(\\s*\\)","message":"Make the empty line with `System.out.println()`, with nothing between the parentheses."}],"forbid":[]},{"task":"Build the first line from three `print` calls, one for `Ready, `, one for `set, ` and one for `go!`, and then end the line. The whole output should be:\n\n```\nReady, set, go!\nRace started.\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        // Three print calls, then end the line.\n\n        System.out.println(\"Race started.\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        // Three print calls, then end the line.\n        System.out.print(\"Ready, \");\n        System.out.print(\"set, \");\n        System.out.print(\"go!\");\n        System.out.println();\n        System.out.println(\"Race started.\");\n    }\n}\n","hints":["`System.out.print(\"Ready, \");` prints the first piece and stays on the line. Mind the space after the comma.","After the third `print`, the line is still open. `System.out.println();` ends it, so `Race started.` gets its own line."],"tests":[{"name":"Output","stdin":"","expect":"Ready, set, go!\nRace started.","hidden":false}],"require":[{"pattern":"System\\.out\\.print\\s*\\(","min":3,"message":"Build the first line from three `System.out.print` calls."}],"forbid":[]}]}