package MyPackage_Test1;
public class Test {
public static void outPut() {
int[] arr = new int[10];
for (int i = 0; i < 10; i++) {
arr[i] = (int) (Math.random() * 100) + 1;
}
int max = arr[0];
int min = arr[0];
System.out.println("随机生成的10个数分别为:");
for (int temp : arr) {
if (max < temp)
max = temp;
if (min > temp)
min = temp;
System.out.print(temp + " ");
}
System.out.println("\n最大值:" + max + "\n最小值:" + min);
}
public static void main(String[] args) {
outPut();
}
}
某次运行结果:
随机生成的10个数分别为:
43 57 86 59 87 98 33 2 64 12
最大值:98
最小值:2
package MyPackage_Test1;
public class Test {
public static void outPut() {
int[] arr = new int[10];
for (int i = 0; i < 10; i++)
{
arr[i] = (int) (Math.random() * 100) + 1;}
int max = arr[0];
int min = arr[0];
System.out.println("随机生成的10个数分别为:");
for (int temp : arr) {
if (max < temp)
max = temp;
if (min > temp)
min = temp;
System.out.print(temp + " ");
}
System.out.println("\n最大值是:" + max + "\n最小值:" + min);
}
public static void main(String[] args) {
outPut();
}
}