10-求数组的最大值和最小值
public class demo006 {
public static void main(String[] args) {
int[] arrs = {1,2,3,5,6,8,9};
//getMax(arrs);
int[] maxMix = getMaxAndMix(arrs);
System.out.println(maxMix[0]);
}
//求 数组的最大值
public static void getMax(int[] arr){
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if(max < arr[i]){
max = arr[i];
}
}
System.out.println("max==="+max);
}
// 求 最大值和最小值 返回的是一个数组
public static int[] getMaxAndMix(int[] arr){
int max = arr[0];
int mix = arr[0];
for (int i = 0; i < arr.length; i++) {
if(max < arr[i]){
max = arr[i];
}
if(mix > arr[i]){
mix = arr[i];
}
}
int[] maxMix = new int[]{max,mix};
return maxMix;
}
}