Question
I have a question here in java To write a recursive method I have a two-dimensional array here The number of rows is equal to
I have a question here in java To write a recursive method I have a two-dimensional array here The number of rows is equal to the number of columns and the array contains Boolean values true and false We will define an area in the array - true region, a maximum collection of adjacent cells that all have a true value. (Cells that are placed diagonally - are not considered adjacent cells)
Example for this array (true = 1 value and false = 0 value) This set has 3 true regions
0 0 0 0 1 0 1 1 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0
A recursive method must be written that accepts as a parameter a Boolean square matrix and returns how many true regions there are in the matrix. If no true regions exist 0 will be returned. true region can consist of one cell.
The method should be recursive without the use of loops. Nor can any auxiliary method contain loops.
You can use overloading and you can also change the array.
No need to do efficiency to the method. Do not use global variables defined outside of methods. I would love to get an explanation of the codes.
I started the code
public class BolleanArr {
public static int TrueReg (boolean[][] arr) { return TrueReg(arr, 0,0); }
private static int TrueReg(boolean[][] arr, int i, int j){
}
}
this tester:
public class Tester { public static void main(){
boolean[][] arr = { {false,false,false,false,true}, {false,true,true,true,false}, {false,false,true,true,false}, {true,false,false,false,false}, {true,true,false,false,false}, };
printArr (arr);
int Result=BolleanArr.TrueReg(arr); System.out.println("Result: "+Result);
}
public static void printArr(boolean [][]arr){ for (int i=0;i output: 0 0 0 0 1 0 1 1 1 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0 Result: 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started