Help /** * Implement the method below, which takes a two-dimensional array of integers * as the input argument and returns the total number of <strong>distinct * pairs</strong> (a, b) where both a and b are even numbers and a is less than * b ({@code a < b} ). Your code should use nested for loops. * * <p> * For example: * </p> * * <pre> * if inputarray = { {9, 10, 3, 4, 3}, {1, 6, 2}, {4, 24, 46, 0}, {15, 9, 45, 57} } then return 21 * note we have 21 distinct pairs within this 2D array as follows * [0, 2],[0, 4],[0, 6],[0, 10],[0, 24],[0, 46],[2, 4],[2, 6], * [2, 10],[2, 24],[2, 46],[4, 6],[4, 10],[4, 24],[4, 46],[6, 10], * [6, 24],[6, 46],[10, 24],[10, 46],[24, 46] * if inputarray = { {1, 6, 1}, {5, 9, 15, 20}, {23, 33, 99} } then return 1 * if inputarray = { {4, 21, 43, 1}, {22, 32, 42, 52} } then return 10 * if inputarray = { {15, 9, 45, 57}, {13, 17, 23} }then return 0 * </pre> * * @param inputarray 2D int input array * @return the number of distinct pairs (a, b) where both a and b are even * numbers and {@code a < b}. */ publicstaticintcountEvenPairs2D(int[][]inputarray){ /* * Your implementation of this method starts here. Recall that : 1. No * System.out.println statements should appear here. Instead, you need to return * the result. 2. No Scanner operations should appear here (e.g., * input.nextInt()). Instead, refer to the input parameters of this method. */
Help
/**
* Implement the method below, which takes a two-dimensional array of integers
* as the input argument and returns the total number of <strong>distinct
* pairs</strong> (a, b) where both a and b are even numbers and a is less than
* b ({@code a < b} ). Your code should use nested for loops.
*
* <p>
* For example:
* </p>
*
* <pre>
* if inputarray = { {9, 10, 3, 4, 3}, {1, 6, 2}, {4, 24, 46, 0}, {15, 9, 45, 57} } then return 21
* note we have 21 distinct pairs within this 2D array as follows
* [0, 2],[0, 4],[0, 6],[0, 10],[0, 24],[0, 46],[2, 4],[2, 6],
* [2, 10],[2, 24],[2, 46],[4, 6],[4, 10],[4, 24],[4, 46],[6, 10],
* [6, 24],[6, 46],[10, 24],[10, 46],[24, 46]
* if inputarray = { {1, 6, 1}, {5, 9, 15, 20}, {23, 33, 99} } then return 1
* if inputarray = { {4, 21, 43, 1}, {22, 32, 42, 52} } then return 10
* if inputarray = { {15, 9, 45, 57}, {13, 17, 23} }then return 0
* </pre>
*
* @param inputarray 2D int input array
* @return the number of distinct pairs (a, b) where both a and b are even
* numbers and {@code a < b}.
*/
publicstaticintcountEvenPairs2D(int[][]inputarray){
/*
* Your implementation of this method starts here. Recall that : 1. No
* System.out.println statements should appear here. Instead, you need to return
* the result. 2. No Scanner operations should appear here (e.g.,
* input.nextInt()). Instead, refer to the input parameters of this method.
*/
Step by step
Solved in 2 steps