Math.random()生成一维随机数组

//一维随机数组

public class RandomArray
{
    public static void main(String[] args)
    {
        int[] nums = new int[(int) (Math.random() * 10)];

        System.out.println("length = " + nums.length); //输出随机数组的长度

        for (int i = 0; i < nums.length; i++)
        {
            nums[i] = (int) (Math.random() * 100)  - (int) (Math.random() * 10);
        }

        // for (int i = 0; i < nums.length; i++)
        //     System.out.println(nums[i]);

        //或者:
        for (int item : nums)
            System.out.println(item);
    }
}
原文地址:https://www.cnblogs.com/profesor/p/12961169.html