java吧 关注:1,255,860贴子:12,747,911
  • 1回复贴,共1

新人求助啊,编译通过执行出错!!!

只看楼主收藏回复

编译行了,结果到了执行却不行了

以下是代码
interface computerWeight{
public double computerWeight();
}
class Television implements computerWeight{
public double computerWeight(){
return 15;
}
}
class Computer implements computerWeight{
public double computerWeight(){
return 5;
}
}
class WashMachine implements computerWeight{
public double computerWeight(){
return 25;
}
}
class Truck{
public static void main (String args[]){
computerWeight[] goods=new computerWeight[3];
int weight=0;
for(int i=0;i<=goods.length;i++)
{
if(i%3==0)
goods [i]=new Television();
else if(1%3==1)
goods [i]=new Computer();
else if(i%3==2)
goods [i]=new WashMachine();
}
System.out.println(weight);
}
}
大神帮忙看看啊,感激不尽


IP属地:浙江1楼2016-11-16 18:34回复
    换个号又发了一遍


    IP属地:北京2楼2016-11-16 18:41
    回复