for (int i = 0; i < array.length; i++) {
int count = 0;
for (int j = 0; j < array.length; j++) {
{
if (array[i] == array[j]) {
count++;
}
}
if (count >= 3) {
System.out.println(array[i] + " exists " + count
+ " times.");
}
}
}
n ( n >= 3), n . , , . , , . : HashMap List... ....
, Integer[] int[] :
Integer[] array = new Integer[] { 1, 2, 1, 1, 1, 3, 3, 3, 2, 2, 4, 5 };
for (int i = 0; i < array.length; i++) {
int count = 0;
if (array[i] != null) {
int compare = array[i].intValue();
for (int j = 0; j < array.length; j++) {
if (array[j] != null) {
if (compare == array[j]) {
array[j] = null;
count++;
}
}
}
if (count >= 3) {
System.out
.println(compare + " exists " + count + " times.");
}
}
}
:
1 exists 4 times.
2 exists 3 times.
3 exists 3 times.
, Integer []. .