public class Array2D {
public static boolean checkForSquare(int[][] arr , int K , int col , int row)
{
if(arr[col][row] == K)
{
if(arr[col][row + 1]== K)
{
if(arr[col + 1][row]== K)
{
if(arr[col + 1][row + 1]== K)
{
return true;
}
}
}
}
return false;
}
public static void main(String[] args)
{
int [][] a = {
{1,2,3,4,4,6,7,12,23,11,13,14},
{0,8,6,4,4,9,1,657,876,8,345, 555},
{0,8,6,75,90,9,1,657,876,8,345, 555},
{1,2,3,6,6,6,7,12,23,11,13,14},
{0,8,6,6,6,9,1,657,5,8,6, 7},
{0,8,6,75,90,9,1,657,4,8,9, 8},
{1,2,3,4,4,6,7,12,29,29,13,16},
{0,8,6,4,4,9,1,0,29,29,13, 14},
{0,8,6,0,0,9,1,657,876,8,3, 25},
{1,2,3,4,4,6,7,12,23,11,13,14},
{0,8,6,4,4,9,1,0,1,8,0, 1},
{0,8,6,0,0,9,1,0,2,8,3, 2},
};
System.out.println(checkForSquare(a, 4, 0, 3)); //checks A
int biggest = 0; //checks B
for(int K = 1 ; K <= 30 ; K ++)
for(int i = 0 ; i < 11 ; i ++)
for(int j = 0 ; j < 11 ; j ++)
{
if(checkForSquare(a, K, i, j))
if(K > biggest)
biggest = K;
}
System.out.println(biggest);
}
}
Comments