Question
A row in a two-dimensional array of boolean values is said to be a happy row if the number of true values in that row
A row in a two-dimensional array of boolean values is said to be a happy row if the number of true values in that row is equal to that row's index number. Write the Java method largestIndexedHappyRow, which takes a two-dimensional array of boolean values called table. You may assume that table has the same number of rows and columns. The method returns the largest index m such that the row of table at index m is a happy row. If there is no happy row in table, the method returns the value -1. For example, the return value for array aa would be 2, the return value for bb would be 1, and the return value for cc would be -1.
aa | 0 | 1 | 2 |
0 | false | false | false |
1 | false | true | false |
2 | true | false | true |
bb | 0 | 1 | 2 |
0 | false | true | false |
1 | false | true | false |
2 | false | true | false |
cc | 0 | 1 | 2 |
0 | true | false | false |
1 | false | true | true |
2 | true | false | false |
-----------------------------------------------------------------------------------------
public static int largestIndexedHappyRow(boolean [][] table) {
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