[java] count water volumn for 2d array

问题遇到的现象和发生背景

I faced the question is that I only know 1d array method, but how can I change the code to suit for 2D array.

Give you a 2D array which means the height of the mountains.
And count the total water volume in this array.
Note: If surrounding elements are higher then a element, then it will be a lake.
The water volume of this lake is equal to (the lowest height of surrounding elements – height of this element)

img

img

img

img

img

img

问题相关代码,请勿粘贴截图

public class moonlake {
public int count_water_volumn(int[][] height);
}

运行结果及报错内容

class GFG{

public static int maxArea(int[] a)
{

int Area = 0;
 
for(int i = 0; i < a.length; i++)
{
    for(int j = i + 1; j < a.length; j++)
    {
        Area = Math.max(
            Area, Math.min(a[i], a[j]) *
                          (j - i));
    }
}
return Area;

}

我的解答思路和尝试过的方法
我想要达到的结果