{"id":"printing-several-lines","slug":"several-lines","title":"Several lines, in order","text":"A program's instructions are called **statements**. Inside `main` they run from top to bottom, one after another, and each `System.out.println` prints one line. Statements like these end with a semicolon `;`, much like a sentence ends with a full stop. (Later modules show statements that hold other statements in braces instead, such as `if` and loops.)\n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        System.out.println(\"3\");\n        System.out.println(\"2\");\n        System.out.println(\"1\");\n        System.out.println(\"Liftoff!\");\n    }\n}\n```\n\n```output\n3\n2\n1\nLiftoff!\n```\n\nSwap two of the lines and the countdown is in the wrong order: the computer does exactly what the statements say, in the order they are written.\n\n### The output has to match exactly\n\nThe checks on this site compare what your program prints with the expected output, character by character. `Liftoff!` and `liftoff!` are different, and so are `Hello, world` and `Hello,world`. The only things ignored are spaces at the very end of a line and empty lines at the very end of the output. Real programs are held to the same standard: another program reading your output won't guess what you meant.\n\n### Less typing\n\n`System.out.println` is long to type, especially on a phone. On a touch screen, the row of keys under the editor has a **sout** key that types `System.out.println();` for you, with the cursor inside the parentheses. Many Java editors have the same shortcut: type `sout` and press Tab.\n","task":"The program prints the first line of a short rhyme. Add the two missing lines so it prints exactly:\n\n```\nSemicolons end the line,\nbraces keep the blocks in line,\nprintln makes the output shine.\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Semicolons end the line,\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Semicolons end the line,\");\n        System.out.println(\"braces keep the blocks in line,\");\n        System.out.println(\"println makes the output shine.\");\n    }\n}\n","hints":["Each line of the rhyme needs its own `System.out.println(\"...\");` statement, below the first one.","Copy the text exactly, including the commas, the full stop and the lower-case first letters."],"tests":[{"name":"Output","stdin":"","expect":"Semicolons end the line,\nbraces keep the blocks in line,\nprintln makes the output shine.","hidden":false}],"require":[{"pattern":"System\\.out\\.println\\s*\\(","min":3,"max":3,"message":"Print each line of the rhyme with its own `System.out.println`, three in all."}],"forbid":[],"more":[{"task":"The morning routine got shuffled. Put the four statements in the right order so the program prints:\n\n```\nWake up\nBrush teeth\nEat breakfast\nStart coding\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Eat breakfast\");\n        System.out.println(\"Wake up\");\n        System.out.println(\"Start coding\");\n        System.out.println(\"Brush teeth\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Wake up\");\n        System.out.println(\"Brush teeth\");\n        System.out.println(\"Eat breakfast\");\n        System.out.println(\"Start coding\");\n    }\n}\n","hints":["The statements run from top to bottom, so the line that should be printed first goes at the top.","Move whole lines. On a phone: select a line, cut it, tap where it should go and paste."],"tests":[{"name":"Output","stdin":"","expect":"Wake up\nBrush teeth\nEat breakfast\nStart coding","hidden":false}],"require":[{"pattern":"System\\.out\\.println\\s*\\(","min":4,"max":4,"message":"Keep the four `System.out.println` statements and only change their order."}],"forbid":[]},{"task":"Print this label exactly, spaces included, with exactly four `System.out.println` statements, one per line:\n\n```\n+-----------------+\n|  JAVA ARENA     |\n|  Part 1: Basics |\n+-----------------+\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        // Print the label here, one line per statement.\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        // Print the label here, one line per statement.\n        System.out.println(\"+-----------------+\");\n        System.out.println(\"|  JAVA ARENA     |\");\n        System.out.println(\"|  Part 1: Basics |\");\n        System.out.println(\"+-----------------+\");\n    }\n}\n","hints":["All four lines are 19 characters wide. Count the spaces: two after the left `|`, and enough before the right `|` to line it up.","The top and bottom lines are the same: a `+`, 17 dashes and a `+`."],"tests":[{"name":"Output","stdin":"","expect":"+-----------------+\n|  JAVA ARENA     |\n|  Part 1: Basics |\n+-----------------+","hidden":false}],"require":[{"pattern":"System\\.out\\.println\\s*\\(","min":4,"max":4,"message":"Use exactly four `System.out.println` statements, one for each line of the label."}],"forbid":[]}]}