public class MaxAndMin {
public static void main(String[] args){
int[] data=new int[]{313, 89, 123, 323, 313, 15, 90, 56, 39};
//打印数组
for (int i=1;i<data.length;i++){
System.out.print(data[i]+",");
}
//求最大值
int max = data[0];
//求最小值
int min = data[0];
for (int i=1;i<data.length;i++){
if (data[i]>max){
max = data[i];
}
if (data[i]<min){
min= data[i];
}
}
System.out.println("最大值:"+max);
System.out.println("最小值:"+min);
}
}
练习题:最大最小值
最新推荐文章于 2024-11-04 20:33:37 发布