代码如下:
import java.util.ArrayList; import java.util.Arrays; public class ExerciseDemo { public static void main(String[] args) { int[][] arr = new int[][]{{1,2,3},{4,5},{6}}; boolean isExist = find(arr,5); System.out.println(isExist); } public static boolean find(int[][] arr,int target){ for (int i = 0; i < arr.length; i++) { for(int j = 0; j < arr[i].length; j++){ if (arr[i][j] == target){ System.out.println("要找的数为:"+arr[i][j]+",是第"+(i+1)+"个数组的第"+(j+1)+"个数字"); return true; } } } System.out.println("要找的数不存在!"); return false; } }