In: Computer Science
in java
Implement a function print2Darray(int[][] array) to print a formatted 4x4 two dimensional integer array. When the array contains {{10, 15, 30, 40},{15, 5, 8, 2}, {20, 2, 4, 2},{1, 4, 5, 0}}, Your output should look like:
{10 15 30 40} {15 5 8 2}{ 20 2 4 2}{ 1450}
Now, implement another function print2DList(ArrayList<ArrayList<Integer>> list) to print a formatted 2D list.
void print2Darray(int[][] array) {
   for(int i = 0; i < array.length; i++) {
       System.out.print("{");
       for(int j = 0; j <
array[0].length; j++) {
          
System.out.print(array[i][j]);
           if(j <
(array[0].length -1))
          
    System.out.print(" ");  
   
       }
      
System.out.print("}");  
   }
}
void print2Darray(ArrayList<ArrayList<Integer>>
list) {
   for(int i = 0; i < list.size(); i++) {
       System.out.print("{");
       for(int j = 0; j <
list.get(0).size(); i++) {
          
System.out.print(list.get(i).get(j));
           if(j <
(list.get(0).size() -1))
          
    System.out.print(" ");  
       }
      
System.out.print("}");  
   }
}