This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes HeadFirst SimpleDotCom compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HeadFirst SimpleDotCom compile" Watch "HeadFirst SimpleDotCom compile" New topic

HeadFirst SimpleDotCom compile

Harold Kanda

Joined: Apr 04, 2008
Posts: 1
Hello, When compiling the following code I get the following errors:; ';' expected
for (int cell : locationCells) {
^ illegal start of expression
return result;
^ illegal start of expression
} // Close Method

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";
} // End loop

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

Any help would be appreciated. Thank you.
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

You need to compile this code with at least Java5. Check that you are not using an old version (javac -version)

[My Blog]
All roads lead to JavaRanch
I agree. Here's the link:
subject: HeadFirst SimpleDotCom compile
It's not a secret anymore!