Solution of the connected regions task. Here is one solution by "Depth-first search". The solution is in a "Regions_DFS_Recursion" class. The solution has a known issue of an overflow of recursive method calling.
There is a second solution, using the BFS algorithm enables more effective implementation without recursion. It is in the "Regions_BFS" class.
The main class is a "CountOfRegions". You can use it for testing both solutions. You may add test cases directly to the "CountOfRegions" class and call both solutions.