Random r = new Random();
int[] num_5 = new int[5];
int[] num_50 = new int[50];
int[] hundred = new int[100];
for(int i=0;i<100;i++){
hundred[i]=i;
}
int sum = 0;
double avg;
for(int i = 0;i< 5;i++){
int num = r.nextInt(100);
num_5[i] = num;
sum += num;
}
avg = (double)sum/5;
Arrays.sort(num_5);
System.out.println("5个int型的随机数:");
for (int i = 0; i < num_5.length; i++) {
int j = num_5[i];
System.out.print(i==4? j:j+",");
}
System.out.println();
System.out.print(" 最大值:"+num_5[4]);
System.out.print(" 最小值:"+num_5[0]);
System.out.print(" 中间值:"+num_5[2]);
System.out.print(" 和:"+sum);
System.out.println(" 平均数:"+avg);
for(int i=0;i<num_50.length;i++){
int temp1 = r.nextInt(100-i);
int temp2 = hundred[99-i];
hundred[99-i] = hundred[temp1];
hundred[temp1] = temp2;
}
for(int i=0;i<num_50.length;i++){
num_50[i] = hundred[99-i];
}
Arrays.sort(num_50);
System.out.println("50个int型的随机数:");
for (int i = 0; i < num_50.length; i++) {
int j = num_50[i];
System.out.print( i==49? j:j+",");
}
//num_50 就是 已经从小打到排序好了的
运行结果
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/48540923dd54564e56210a76b7de9c82d1584f3d?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)