为什么不用int
int tempcode = (int)Math.random()*10000+10000
在这里好像用不到取模
((10000*Math.random()) 取得就是0-10000的数把

解决方案 »

  1.   

    这位兄台错了!Math.random()得到的是一个0-1之间的小数,再乘以10000,得到的是0-10000之间的double型数据。不是我要求的整数。
    另外,你说的用int tempcode = (int)Math.random()*10000+10000这种方式我也试过,但还是不行。提示错误是“possible loss of precision”。真是气人,本来我也以为这样应该是可以的啊。
      

  2.   

    String tempcode=String.valueOf(10000+(int)(10000*Math.random() ));
    把你的方法改成这个吧
    我试过拉,可以得到10000-20000之间的整数
      

  3.   

    String tempcode=String.valueOf( 10000 + (new Random(10000)).nextInt() );
      

  4.   

    郁闷
    你用我刚才的
    加个括号试试好马、
    int tempcode = (int)(Math.random()*10000)+10000
    谢谢