package com.heima.array;
public class Demo02_Array {
/**
* @param args
*/
public static void main(String[] args) {
int[] arr1 = {12,34,45,65,79};
print(arr1);
int max = getMax(arr1);
int min = getMin(arr1);
}
//1:数组遍历的方法提取
public static void print(int[] arr){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
//2:获取数组中的最大值
public static int getMax(int[] arr){
int max;
max = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr[0] < arr[i]) {
max = arr[i];
}
}
System.out.println(max);
return max;
}
//3:获取数组中的最小值
public static int getMin(int[] arr){
int min = arr[0];
for (int i = 0; i < arr.length; i++) {
if (min > arr[i]) {
min = arr[i];
}
}
System.out.println(min);
return min;
}
}
|
|