- package com.itheima;
- public class test3 {
- /**
- * 3.定义一个二维int数组,编写代码获取最小元素
- * @param args
- */
- public static void main(String[] args) {
-
- int[][] arr = {{12,34},{75,9,78,35},{24,65,44,9,3},{43,56,21,8}};
-
- int min = getmin(arr);
- System.out.println("最小元素为:"+min);
- }
- public 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;
- }
- }
复制代码
|