• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

HeadFirst SimpleDotCom compile

 
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.
 
Sheriff
Posts: 14691
16
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)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!