//一维随机数组

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);
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2021-07-04
  • 2021-08-27
  • 2021-06-24
  • 2021-09-28
  • 2021-05-16
猜你喜欢
  • 2022-12-23
  • 2021-07-19
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-12-03
相关资源
相似解决方案