Advertisement
Yuvalxp8

2D Array

Oct 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. public class Array2D {
  2.    
  3.     public static boolean checkForSquare(int[][] arr , int K , int col , int row)
  4.     {
  5.         if(arr[col][row] == K)
  6.         {
  7.             if(arr[col][row + 1]== K)
  8.             {
  9.                 if(arr[col + 1][row]== K)
  10.                 {
  11.                     if(arr[col + 1][row + 1]== K)
  12.                     {
  13.                         return true;
  14.                     }
  15.                 }
  16.             }
  17.         }
  18.             return false;
  19.     }
  20.  
  21.  
  22.     public static void main(String[] args)
  23.     {
  24.         int [][] a = {
  25.                 {1,2,3,4,4,6,7,12,23,11,13,14},
  26.                 {0,8,6,4,4,9,1,657,876,8,345, 555},
  27.                 {0,8,6,75,90,9,1,657,876,8,345, 555},
  28.                 {1,2,3,6,6,6,7,12,23,11,13,14},
  29.                 {0,8,6,6,6,9,1,657,5,8,6, 7},
  30.                 {0,8,6,75,90,9,1,657,4,8,9, 8},
  31.                 {1,2,3,4,4,6,7,12,29,29,13,16},
  32.                 {0,8,6,4,4,9,1,0,29,29,13, 14},
  33.                 {0,8,6,0,0,9,1,657,876,8,3, 25},
  34.                 {1,2,3,4,4,6,7,12,23,11,13,14},
  35.                 {0,8,6,4,4,9,1,0,1,8,0, 1},
  36.                 {0,8,6,0,0,9,1,0,2,8,3, 2},
  37.         };
  38.        
  39.         System.out.println(checkForSquare(a, 4, 0, 3)); //checks A
  40.        
  41.         int biggest = 0;                    //checks B
  42.         for(int K = 1 ; K <= 30 ; K ++)
  43.             for(int i = 0 ; i < 11 ; i ++)
  44.                 for(int j = 0 ; j < 11 ; j ++)
  45.                 {
  46.                     if(checkForSquare(a, K, i, j))
  47.                         if(K > biggest)
  48.                             biggest = K;
  49.                 }
  50.         System.out.println(biggest);
  51.        
  52.     }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement