public class Zhaoshu {
public static void main(String[] args) {
int[] a = new int[10];
for(int i = 0; i < a.length; i++) {
a[i] = (int) (Math.random() * 99 + 1);
System.out.print(a[i] + "\t");
}
System.out.println();
int max, min;
max = min = a[0];
for(int i = 1; i < a.length; i++) {
if(a[i] > max) {
max = a[i];
}
else if(a[i] < min) {
min = a[i];
}
}
System.out.println("最大值: " + max);
System.out.println("最小值: " + min);
}
}
随机生成几个数然后找出最大的和最小的
最新推荐文章于 2023-03-13 00:12:09 发布