java怎么产生随机个数并存入到数组中?

img


想知道这里应该怎么把随机数存进去?数组中的个数是键盘输入进去,根据元素个数产生随机数然后存入数组,这里不清楚具体怎么做?

math.random() 产生随机数,然后保存到数组,跟你输入是一样的呀

img

  public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入产生随机数个数:");
        int count =scan.nextInt();
        int a[]=new int [count];
        for(int i=0;i<count;i++){
            a[i]=(int) (Math.random() * 100);
        }
        Arrays.sort(a);
        System.out.print("倒叙结果是"+"\t");
        for(int i=count-1;i>=0;i--){
            System.out.print(a[i]+"\t");
        }

}