• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

HeadFirst SimpleDotCom compile

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

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.
Posts: 14691
Eclipse IDE VI Editor Ubuntu
  • 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)
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!