刚才那个是一维数组的,现在这个是二维数组的- package com.test;
- public class GetMin {
- public static void main(String[] args) {
- int[][] arr = new int[][]{{1,2,5},{4,5,3},{10,3,5},{6,3,1},{1,2,8},{6,0,7},{-1,20,10}};
- System.out.println(getMin(arr));
- }
- private static int getMin(int[][] arr){
- int min = arr[0][0];
- for (int i = 0; i < arr.length; i++) {
- for (int j = 0; j < arr[i].length; j++) {
- if(arr[i][j]<min){
- min=arr[i][j];
- }
- }
- }
- return min;
- }
- }
复制代码 |