1 public class Main {
2 public static void main(String[] args) {
3 // write your code here
4 int[] arr = {4,3,2,3,5,9,1,10};
5 int max = getMax(arr);
6 int min = getMin(arr);
7 System.out.println("最大值:"+max);
8 System.out.println("最小值:"+min);
9 }
10 //获取最大值
11 static int getMax(int[] arr){
12 int max = arr[0];
13 for (int i= 1;i<arr.length;i++){
14 if (arr[i]>max){
15 max = arr[i];
16 }
17 }
18 return max;
19 }
20 //获取最小值
21 static int getMin(int[] arr){
22 int min = arr[0];
23 for (int i=1;i< arr.length;i++){
24 if (min>arr[i]){
25 min = arr[i];
26 }
27 }
28 return min;
29 }
30 }