请问此空填什么才不会使得a=0呢?想了老久实在想不出了,求各位大虾帮帮忙啊~谢谢~~~

解决方案 »

  1.   


    int a = (int)Math.random() * M + N;M为任意数,N为非0数。
      

  2.   

     int a = (int)Math.random() * X + Y;(Y!=0)
      

  3.   

    相当于int a = 0 * ?;
    只能如1楼所说方法了。
      

  4.   

    问题补充,抱歉木有把问题说详细-_-|||,由于(int)的优先级较高,所有不论Math.random()所产生的值为多少都会因强制转换使得(int)Math.random()这段为0,我想要使得a为一个非零的随机数,但只能填此空(int)Math.random() * __________;使其满足条件,所以就不知道怎么做了~~~~
      

  5.   

    Math.random();产生的随机数的范围在0=<Math.random()<1之间,也就是他有可能产生的随机数是0如果为0那么0X任何数得0所以你这个填什么都有可能为0啊.
      

  6.   

    一楼的方法a不是随机数啊!难道,额,突然想到
    int a = (int)Math.random() *M+(int)(Math.random()*10),不过这样貌似太不专业了点
      

  7.   

    直接让前面的废掉,自己写一个random
    int a =  (int)Math.random() + (int)(Math.random()*100) ;
      

  8.   


    int a =  (int)Math.random()*0 + (int)(Math.random()*100) ;
      

  9.   

    到这时候才补充啊,这个也挺简单的。int a = (int)Math.random() * M + (int)(Math.random() * 10);
      

  10.   

    这个仍然可能得到0
    int a =  (int)Math.random() +(int)(Math.random()*100)+1
      

  11.   

    Math.random() 方法返回值的取值范围是[0, 1),主要考察这个知识点
      

  12.   

    这个题目如果是int a = (int)(Math.random() *60)的话就不是0了。但是这个题目是一到填空题题目定好了这个样子int a = (int)Math.random() * 所有要改成int a = (int)Math.random() *N+(int)(Math.random()*M ),N为任意数,M是你想得到的那个范围的最大值
      

  13.   

    int a =  (int)Math.random()*0 + (int)(Math.random()*100) ;
      

  14.   

    后面加上一个数吗  Math.random() * n + m;
      

  15.   

    兄弟、我实在忍不住了、发表一下。
    假如那个空只能填一个字母或者数字的话,a=0这个事实是改变不了的了,因为(int)Math.random()已经为0了。
    假如那个空能随便填的话,a=0或a!=0按照楼上们的解答都能随便实现。
    就这么简单。
      

  16.   

    如果要不择手段的话就写成:Math.random()*0 + i;(i != 0)
      

  17.   

    但最好还是写成(int)Math.random() * i + 1;因为Math.random()的返回值为[0, 1]