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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!