高手帮忙看看有什么问题 过不了编译器

public class SimpleDotCom {
public static void main(String[] args) {
int[] locationCells;
int numOfHits = 0;

public String checkYourself (String stringGuess) {
int guess = Integer.parseInt(stringGuess);
String result = "miss";
for(int cell : locationCells) {
if(guess == cell) {
result = "hit";
numOfHits ++;
break;
}
}
if(numOfHits == locationCells.length) {
result = "kill";
}
System.out.println(result);
}
public void setLocationCells (int[] locs) {
locationCells = locs;
}
}
}

错误提示:第7行 Multiple markers at this line
- Syntax error on token "(", ; expected
- Illegal modifier for parameter checkYourself; only final is
permitted
第22行 Multiple markers at this line
- Syntax error on token ")", ; expected
- void is an invalid type for the variable
setLocationCells

不能再方法中嵌套方法。

public class SimpleDotCom {
public static void main(String[] args) {
int[] locationCells;
int numOfHits = 0;

if(numOfHits == locationCells.length) {
result = "kill";
}
System.out.println(result);
}

}
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;
}
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-10-02
下边貌似多了一个括弧