请问怎么随机数老是全0???? 而且引入的 import java.Math.*;他提示没用到??import java.math.*;
public class bubble_sort {

public static void main(String[] args) {



for(int x=0; x<10; x++)
System.out.print((int)(Math.random())+ " ");
  

}
}

解决方案 »

  1.   

    当然不行了额java.lang.Object
      java.lang.Mathstatic double random() 
              Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. 产生的是 《1 and 》0的小数
    强制转换(int)(Math.random())当然是0啦
      

  2.   

    import java.math.*;
    public class bubble_sort {

    public static void main(String[] args) {



    for(int x=0; x<10; x++)
                                int i=(int)(Math.random()*8)+1;
    System.out.printl(" "+i);
      

    }
    }
    从8到1的整数!
      

  3.   

    谢谢  jnzsk 偶正找产生一定范围随机数的法子呢