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

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

猜你喜欢

转载自blog.csdn.net/weixin_34077371/article/details/93565900