This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HeadFirst SimpleDotCom compile  RSS feed

 
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
Boost this thread!