public int islandPerimeter(int[][] grid){

int perimeter = 0;

for(int i = 0; i < row; i++){

for(int j = 0; j < col; j++){

if(grid[i][j] == 1){

if(j - 1 < 0 || grid[i][j - 1] == 0) perimeter++;

if(j + 1 >= col || grid[i][j + 1] == 0) perimeter++;

if(i - 1 < 0 || grid[i - 1][j] == 0) perimeter++;

if(i + 1 >= row || grid[i + 1][j] == 0) perimeter++;

}

}

}

return perimeter;

}

i calculate the perimeter by the neiborhoods, if a ceil == 1, and its (left or right or top or buttom) neiborhood is water

,perimeter++.