Write methods called equals2D methods The methods should acc

Write methods called equals2D methods. The methods should accept a pair of two-dimensional arrays of integers/Strings as parameters. It return true if the arrays contain the same elements in the same order. If the arrays are not the same length in either dimension, your method should return false.

**Just write methods. No class**

Solution

   public static boolean equals2D (int a[][], int b[][]){
       if(a.length != b.length || a[0].length != b[0].length){
           return false;
       }
       else{
           for(int i=0; i<a.length; i++){
               for(int j=0; j<a[i].length; j++){
                   if(a[i][j] != b[i][j]){
                       return false;
                   }
               }
           }
           return true;
       }
      
   }
   public static boolean equals2D (String a[][], String b[][]){
       if(a.length != b.length || a[0].length != b[0].length){
           return false;
       }
       else{
           for(int i=0; i<a.length; i++){
               for(int j=0; j<a[i].length; j++){
                   if(!a[i][j].equals(b[i][j])){
                       return false;
                   }
               }
           }
           return true;
       }
      
   }

Write methods called equals2D methods. The methods should accept a pair of two-dimensional arrays of integers/Strings as parameters. It return true if the array

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site