wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HeadFirst SimpleDotCom compile" Watch "HeadFirst SimpleDotCom compile" New topic
Author

HeadFirst SimpleDotCom compile

Harold Kanda
Greenhorn

Joined: Apr 04, 2008
Posts: 1
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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
 
 
subject: HeadFirst SimpleDotCom compile
 
Similar Threads
Code errors
Enhanced for loop
i am still getting compile time error in this program plz give me solution
Getting 6 errors with the use of result(noob)
still this code gives compile time error