I wish to make a function that checks whether theres any number in the array that exist three or more times.
So example this array:
4 – 6 – 14 – 8 – 6 – 15 – 14 – 15 – 13
– 10 –
Shouldnt output anything, but this:
4 – 6 – 14 – 8 – 6 – 15 – 14 – 15 – 14
– 10 –
Should systemout print output that the number 14 exists three times.
How should this be done? I started making a for loop,
for(int i=0; i<array.length; i++){
}
And then I got stuck, how can i make this?
This programm outputs n times (for n >= 3) that the an element exists n times. You should add a logic that checks whether an element has already been checked. But maybe you can go on by yourself now. Hint: Use a HashMap or a List… or….
Other solution that needs
Integer[]instead ofint[]and is faster:Output:
So copy your array into a Integer[] array first. The latter algorithm fixes also the problem with the output.