File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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