Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialbehar
10,799 PointsJava: .class expected?
Im working on a TTT game, and im trying to make the AI capable of sellecting from an array of multiple moves. My code:
public int multipleMoves(int[] board, int[] possibleMoves) {
if (possibleMoves.length != 0) {
return int whyIsThisNotWorking = new Random().nextInt(possibleMoves.length);
}
}
Tho this code cant compile, and it stops with the error message: java: .class expected.. This it says the error is occuring on the variable itself, but i dont get this. Thanks in advance!
1 Answer
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsDon't declare a variable in the return statement. Java already knows you want to return an int from the method signature. Just return the value directly. Don't forget you must always have a return value (or failing that, throw an exception). Right now nothing happens when the condition in your if statement is false. The compiler is going to complain about that too. For example:
public int multipleMoves(int[] board, int[] possibleMoves) {
if (possibleMoves.length != 0) {
return new Random().nextInt(possibleMoves.length);
}
return 0;
}
behar
10,799 Pointsbehar
10,799 PointsGot it, ty!