public class HelloWorld{
public static void main(String[] args){
int[] a = new int[5];
a[0] = (int) (Math.random() * 100);
a[1] = (int) (Math.random() * 100);
a[2] = (int) (Math.random() * 100);
a[3] = (int) (Math.random() * 100);
a[4] = (int) (Math.random() * 100);
System.out.println("数组中的各个随机数是:");
for (int i = 0; i < a.length; i++)
System.out.println(a[i]);
System.out.println("增强for循环找到最小值: ");
int temp=a[0];
for(int i:a){
if(i<temp){
temp=i;
}
}
System.out.println("最小值为:"+temp);
}
}
Java基础-增强for循环找到随机数组中最小值
最新推荐文章于 2022-06-08 21:59:51 发布