java怎么在5X5的数组里随机位置生成5个1-100的随机数并复制

2025-03-20 21:03:27
推荐回答(1个)
回答(1):

private static void RandomTest() { Random rand=new Random(); int num=0; int save[]=new int[6]; int i=1; while(i<6) { num=(int)(rand.nextDouble()*(100000-10000)+10000); save[i]=num;//放入数组 System.out.println("第"+i+"个数:"+save[i]);//从数组拿出 i++; } }