下面这两句有什么不同么?
      ori[i]=(int)Math.random()*10;   (1)
      ori[i]=(int)(Math.random()*10;)  (2)
 放在如下的循环中
        for(int i=0;i<=3;i++){
    ori[i]=(int)Math.random()*10;
//ori[i]=(int)(Math.random()*10);
for(int j=0;j<=i-1;j++){
  if((i!=j)&&(ori[i]==ori[j])){
    i=i-1;
break;
  }
}
  }
   时,为啥第一句是是死循环呢????
  想不明白…………

解决方案 »

  1.   

    (int)Math.random()等于0
    因为Math.random()比1小
      

  2.   

    Math.random()生成的数在0、1之间,你第一种方式将Math.random()先强制转换,结果一定是0,ori[i]=(int)Math.random()*10效果实际上就是ori[i]=0;这样就不难理解为什么一直是死循环了
      

  3.   

    修改成 ori[i]=(int)(Math.random()*10)
      

  4.   

    XXKKFF(齐次边界条件有界弦自由振动方程混合问题的分离变量法)说的好!
      

  5.   

    我是来学习的,我看了楼上的回复还没有明白,你说的到是很对,但是好象那不是产生死循环的原因吧,也就是ori[i]全部元素都是0罢了.