Java Arena
Step 4 of 5

Comments

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:

  • // starts a comment that runs to the end of the line.
  • /* starts a comment that runs until the next */, even across several lines.
public class Main {
    public static void main(String[] args) {
        // This is a note. Java skips this line.
        System.out.println("Visible");
        // System.out.println("Hidden");
        /* A block comment
           can span several lines. */
        System.out.println("Also visible");
    }
}
Output
Visible
Also visible

The 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.

Inside quotes, // is ordinary text: System.out.println("// not a comment"); prints // not a comment.

Your task

Challenge 1 of 3

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:

Shopping list:
- bread
- milk

Challenge 2

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:

Program version 1

Challenge 3

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:

Welcome, player one!
Press Check to begin.