随机产生0~9的一个整数:
int random=(int)(Math.random()*10);
该怎样理解??
如果随机产生0~99的一个整数又该怎样写??
请教——————

解决方案 »

  1.   

    int random=(int)(Math.random()*100); 
      

  2.   

    Math.random()函数获得大于或等于 0.0 但小于 1.0 的伪随机 double 值
    0~99
    int random=(int)(Math.random()*100); 
      

  3.   

    int random=(int)(Math.random()*100); 
    Math.random()生成0-1浮点数,乘以100,则生成0-100的浮点数
    再经过强制类型转换
      

  4.   

    该怎么理解?看看API文档就明白了撒。
      

  5.   

    0 <= x < 1
    放大100倍不就是 0<= x < 100了么,期间的整数就是0~99了