jasmine667 2010-11-10 13:28
浏览 199
已采纳

谁来看看编译器到底出了什么问题?实在找不出错误啊!

下面是源代码,用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]

  • 写回答

3条回答 默认 最新

  • ethenjean 2010-11-10 15:06
    关注

    英文版你要么?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀