Skirsch Skirsch - 1 month ago 6
Java Question

I keep getting an <identifier> expected error

I get an

<identifier>
expected error running this code:

public class RockPaperScissors {

public static double aiChoice() {
return Math.random();
}

System.out.println(aiChoice);
}

Answer

The problem is that you have System.out.println(aiChoice); outside any methods and try to print a method without calling it. Instead, put your System.out.println into the main method, like this:

public static void main(String [ ] args) {
    System.out.println(RockPaperScissors.aiChoice());
}

Note the parantheses after aiChoice, making sure that you call the method. If your main method does not know about the RockPaperScrissors class, then make sure to

import RockPaperScrissors;

at the start of the file where you have your main method.

Comments