{"id":"printing-comments","slug":"comments","title":"Comments","text":"A **comment** is a note for people reading the code. The compiler skips it completely, so it never changes what the program does. Java has two kinds:\n\n- `//` starts a comment that runs to the end of the line.\n- `/*` starts a comment that runs until the next `*/`, even across several lines.\n\n```java\npublic class Main {\n    public static void main(String[] args) {\n        // This is a note. Java skips this line.\n        System.out.println(\"Visible\");\n        // System.out.println(\"Hidden\");\n        /* A block comment\n           can span several lines. */\n        System.out.println(\"Also visible\");\n    }\n}\n```\n\n```output\nVisible\nAlso visible\n```\n\nThe fifth line shows a common trick: putting `//` in front of a statement **comments it out**. The statement stays in the file, so it's easy to bring back, but it doesn't run. That's handy when you want to try the program without one line.\n\nInside quotes, `//` is ordinary text: `System.out.println(\"// not a comment\");` prints `// not a comment`.\n","task":"The shopping list has a line that doesn't belong on it. Comment out that line with `//` (don't delete it) so the program prints:\n\n```\nShopping list:\n- bread\n- milk\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Shopping list:\");\n        System.out.println(\"- bread\");\n        System.out.println(\"- homework\");\n        System.out.println(\"- milk\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        System.out.println(\"Shopping list:\");\n        System.out.println(\"- bread\");\n        // System.out.println(\"- homework\");\n        System.out.println(\"- milk\");\n    }\n}\n","hints":["The line to switch off is the one that prints `- homework`.","Put `//` at the start of that line. The rest of the line becomes a comment."],"tests":[{"name":"Output","stdin":"","expect":"Shopping list:\n- bread\n- milk","hidden":false}],"require":[{"pattern":"//\\s*System\\.out\\.println\\s*\\(\\s*\"- homework\"","raw":true,"message":"Turn the `- homework` line into a comment with `//` instead of deleting it."}],"forbid":[],"more":[{"task":"Someone wrote notes straight into the program, so it doesn't compile. Turn the three lines of notes into one block comment, starting with `/*` and ending with `*/`. Then the program compiles and prints:\n\n```\nProgram version 1\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        Notes for later:\n        add a greeting\n        print the date\n        System.out.println(\"Program version 1\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        /* Notes for later:\n        add a greeting\n        print the date */\n        System.out.println(\"Program version 1\");\n    }\n}\n","hints":["Java tries to read the notes as code, and they aren't Java. Inside a comment they're skipped.","Put `/*` before `Notes for later:` and `*/` after `print the date`."],"tests":[{"name":"Output","stdin":"","expect":"Program version 1","hidden":false}],"require":[{"pattern":"/\\*[\\s\\S]*Notes for later[\\s\\S]*print the date[\\s\\S]*\\*/","raw":true,"message":"Keep the notes, inside one block comment: `/*` before them and `*/` after them."}],"forbid":[]},{"task":"This program should greet the player and then give an instruction, but the greeting never appears: a comment ends in the wrong place and hides it. Fix the comments so the notes stay comments and the program prints:\n\n```\nWelcome, player one!\nPress Check to begin.\n```\n","kind":"code","seed":"public class Main {\n    public static void main(String[] args) {\n        /* Say hello to the player.\n        System.out.println(\"Welcome, player one!\");\n        Then give the first instruction. */\n        System.out.println(\"Press Check to begin.\");\n    }\n}\n","solution":"public class Main {\n    public static void main(String[] args) {\n        /* Say hello to the player. */\n        System.out.println(\"Welcome, player one!\");\n        /* Then give the first instruction. */\n        System.out.println(\"Press Check to begin.\");\n    }\n}\n","hints":["The block comment starts at `/*` on the first line and only ends at the `*/` two lines further down, so the greeting is inside it.","End the first comment right after `Say hello to the player.`, and make `Then give the first instruction.` a comment of its own."],"tests":[{"name":"Output","stdin":"","expect":"Welcome, player one!\nPress Check to begin.","hidden":false}],"require":[{"pattern":"Then give the first instruction","raw":true,"message":"Keep the note `Then give the first instruction.` as a comment."}],"forbid":[]}]}