下面是源代码,用javac SimpleDotComTestDrive.java命令编译的时候,红色语句出现错误,是什么原因啊?
public class SimpleDotComTestDrive{
public static void main(String[] args){
int numOfGuesses=0;
GameHelper helper=new GameHelper();
SimpleDotCom theDotCom=new SimpleDotCom();
int randomNum=(int) (Math.dandom()*6);
[color=red]int[] locations=(randomNum,randomNum+1,randomNum+2);[/color]
theDotCom.setLocationCell(locations);
boolean isAlive=true;
while(isAlive==true){
String guess=helper.getUserInput("enter a number");
String result=theDotCom.checkYourself(guess);
numOfGuesses++;
if(result.equals("Kill")){
isAlive=false;
System.out.println("You took "+numOfGuesses+"guesses");
}//close if
}//close while
}//close main
class SimpleDotCom{
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;
} }
if (numOfHits==locationCells.length){
result="Kill";
}
System.out.println(result);
return result;
}
}
}//close public
图5 编译的结果:
[img]http://dl.iteye.com/upload/attachment/345816/e6b7258f-2cbe-3e79-8ec7-d1d91475032d.png[/img]