public class SearchIn2DArr { public static void main(String[] args) { int[][] num=new int[][]{ {1,2,3}, {4,5,6,33,45,52}, {7,8,9,23,11,12,13}, {122,33} } ; System.out.println(max(num)); System.out.println(even(num)); // int target=23; // int[] ans=search(num,target); // System.out.println(ans); } // static int[] search(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) { // return new int[]{i,j}; // // } // } // } // return new int[]{-1,-1}; // } static int max(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 (arr[i][j]>max) { max=arr[i][j]; } } } return max; } static int[] even(int[][] arr) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { if (arr[i][j]%2==0) { System.out.println("It is even number"+arr[i][j]); } if(arr[i][j]%2!=0){ System.out.println("It is odd number"+arr[i][j]); } } } return null; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter