min and max number in multidimensional array

Solutions on MaxInterview for min and max number in multidimensional array by the best coders in the world

showing results for - "min and max number in multidimensional array"
Leah
06 Aug 2019
1import java.util.Arrays;
2
3public class MinAndMaxNumInMultiDimensionalArray {
4    public static void main(String[] args) {
5        int[][] data = {{3, 2, 5},
6            {1, 4, 4, 8, 13},
7            {9, 1, 0, 2},
8            {0, 2, 6, 3, -1, -8} };
9
10        int maximum = Integer.MIN_VALUE;
11        int minimum = Integer.MAX_VALUE;
12
13        for(int i = 0; i < data.length; i++) {
14            Arrays.sort(data[i]);
15
16    if(data[i][0] < minimum) minimum = data[i][0];
17if(data[i][data[i].length - 1] > maximum) maximum = data[i][data[i].length - 1];
18        }
19
20        System.out.println("Minimum = " + maximum);  
21        System.out.println("Maximum = " + minimum); 
22    }
23}
24
25
26
27OR++++++++++++++++++++++++++++++++
28import java.util.Arrays;
29
30public class MinAndMaxNumInMultiDimensionalArray {
31    public static void main(String[] args) {
32    int[][] data = {{2, 4, 5}, {3,0,7},{1,2,9}};
33    
34    int min = abc[0][0];
35    
36    for(int i = 0; i < 3; i++){
37    
38    for(int j = 0; j < 3; j++){
39    
40    if(abc[i][j] < min){
41    
42    min = abc[i][j];
43    }
44     }
45      }
46    
47    
48