dd = Math.random()*52;
nums = (int)Math.rint(dd);nums的范围应该是0-51
可为什么会有52出现?
为什么?

解决方案 »

  1.   

    rint
    public static double rint(double a)返回最接近参数并等于某一整数的 double 值。如果两个同为整数的 double 值都同样接近,那么结果取偶数。特殊情况如下: 
    如果参数值已经是整数,那么结果与参数相同。 
    如果参数为 NaN、无穷大、正 0 或负 0,那么结果与参数相同。这是API中的说明。
      

  2.   

    当然了Math.rint()应该是向上取整数吧。
      

  3.   

    直接用
    nums = (int)(Math.random()*52)