Im having trouble creating a method that takes as input a two-dimensional integer array. The output will be a second two-dimensional array with equal number of elements in the corresponding rows of the first array, this time the type of the elements will be booleans. The values of the output will correspond to the value existing in the array multiple times.
Here I have provided an example:
If inputArray is the output of the method would be the following boolean array: [[ 4, 9], [ 9, 5, 3]]. Since 9 is in the input array twice, both positions in the output that correspond to those two instances are true, all of the other values only occur once, so their values are false like this [[ false, true ], [ true, false, false]].
The code is provided below.
class SearchAndPrint{
public static void main(String[] args){
int[][] testCase =
{{4, 9, 10, 9},
{5, 4, 7, 10, 11},
{4, 2}};
System.out.println("The test case array: ");
for (int i=0; i<testCase.length; i++){
for (int j=0; j<testCase[i].length; j++){
System.out.print(testCase[i][j]+" ");
}
System.out.println();
}
boolean[][] founds = gridOfMultiples(testCase);
System.out.println("Positions with repeated numbers are marked below: ");
}
public static boolean[][] gridOfMultiples(int[][] inputArray){
boolean [][] gridOfMultiples = new boolean[inputArray.length][];
Arrays.fill(gridOfMultiples, false);
for(int i=0; i<inputArray.length.length; i++){
for (int j=0; j<inputArray.length[i]; j++){
if(inputArray.length[i][j]==inputArray.length[i][j]){
gridOfMultiples[i][j] = true;
break;
}
return gridOfMultiples;
}
}
return whoIsPrime;
}
inputArray.length[i][j] == inputArray.length[i][j]which is unfortunately both useless (it's always true) and invalid (doesn't compile).