遍历二维数组求出最大值和最小值:
- package Temp;
- public class myInt {
- /**
- * @param args
- */
- public static void main(String[] args) {
- int[][] arr= {{23,34,87,78},{12,-34,-766,56},{23,54,999,44}};
- int min = arr[0][0];
- int max = arr[0][0];
- for(int[] arrTemp:arr)
- {
- for(int i: arrTemp)
- {
- if(i<min)
- {
- min = i;
- }
- if(max < i)
- {
- max = i;
- }
- }
- }
-
- System.out.println("Min:"+min);
- System.out.println("Max:"+max);
- }
- }
复制代码 |
|