Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HeadFirst SimpleDotCom compile

 
Harold Kanda
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, When compiling the following code I get the following errors:

SimpleDotCom.java:13; ';' expected
for (int cell : locationCells) {
^
SimpleDotCom.java:25: illegal start of expression
return result;
^
SimpleDotCom.java:26: illegal start of expression
} // Close Method



Code
-------------
public class SimpleDot {

int[] locationCells;
int numOfHits = 0;

public void setLocationCells(int[] locs){
locationCells = locs;
}

public String checkYourself(String stringGuess) {
int guess = Integer.parseInt(stringGuess);
String result = "miss";
for (int cell : locationCells) {
if (guess == cell) {
result = "hit";
numOfHits++;
break;
}
} // End loop

if (numOfHits == locationCells.length) {
result = "kill";
}
System.out.println(result);
return result;
} // Close Method
} // Close Class


Any help would be appreciated. Thank you.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to compile this code with at least Java5. Check that you are not using an old version (javac -version)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic