class Demo{/*数组获取最值(获取数组中的最大值最小值)*/public static void main(String args[]){ int Max,Min; int [] arr = {2,1,3,5,4}; Max = Min =arr[0]; for(int i =0; i<arr.length;i++){ if(Max < arr[i]){ Max = arr[i]; } if(Min > arr[i]){ Min = arr[i]; } } System.out.println(Max); System.out.println(Min); }}