简单的求数组的最大值及最小值

int[] arr={1,2,43,45,6,96,2};
int max=-1;
int min=-1;
for (int i = 0; i < arr.length; i++) {
      int temp = arr[i];
      if(i == 0) {
          max = temp;
          min = temp;
       }
       if (temp > max) {
           max = temp;
       }
       if (temp < min) {
           min = temp;
       }
System.out.println("min is"+min);
System.out.println("max is"+max);

 }

原文地址:https://www.cnblogs.com/jokerpan/p/3844396.html