首页 > 其他分享 >ArrayAssignment

ArrayAssignment

时间:2024-09-24 09:51:59浏览次数:7  
标签:Random ArrayAssignment int random nextInt public out


package com.shrimpking.t3;

import java.util.Random;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2024/9/15 15:57
 */
public class ArrayAssignment
{
    public static void main(String[] args)
    {
        //创建随机对象
        Random random = new Random();
        int[] a = null;
        a = new int[random.nextInt(10)];
        System.out.println("数组的长度是=" + a.length);

        for (int i = 0; i < a.length; i++){
            //100以内的随机数
            a[i] = random.nextInt(100);
            System.out.printf("a[%d] = %d%n",i,a[i]);
        }
    }
}

标签:Random,ArrayAssignment,int,random,nextInt,public,out
From: https://blog.51cto.com/u_15356972/12097183

相关文章