第三题:二维数组求最大值
public class Test3 {
public static void main(String[] args) {
int[][] arr = { { 2, 3, 5 }, { 54, 41, 3 }, { 8, 16, 42 } };
System.out.println(getMax(arr));
}
public static int getMax(int arr[][]) {
int max = arr[0][0];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (max < arr[i][j]) {
max = arr[i][j];
}
}
}
return max;
}
} |