Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are the functions of top management?

Answered: 1 week ago

Question

Bring out the limitations of planning.

Answered: 1 week ago

Question

Why should a business be socially responsible?

Answered: 1 week ago

Question

Discuss the general principles of management given by Henri Fayol

Answered: 1 week ago

Question

What is the environment we are trying to create?

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago