Question: This is my code: public static String countArray (int[] array) { String result = ; for (int i = 0; i if (array[i] >= 2
This is my code:
public static String countArray (int[] array) {
String result = "";
for (int i = 0; i
if (array[i] >= 2 && array[i]
int counter = 1;
for (int j = i+1; j
if (array[i] == array[j]) {
counter++;
array[j] = -1;
}
}
result += array[i] + ": " + counter + " ";
}
}
return result;}
For some reason, the test cases 1 and 3 are failing. I cannot use any other libraries. The code is supposed to print out the number of occurrences of each element in an array. The element is great than or equal to 2, less than 100 and is an even number. What am i doing wrong???? I have tried other chegg responses to this question and they have all failed test cases 1 and 3, or they use other libraries and the code is not simple.
![This is my code: public static String countArray (int[] array) { String](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3c38aabf54_33866f3c38a1b07f.jpg)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
