xxxxxxxxxx
import java.util.*;
//saiyam9934
public class ElementCount {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 1, 2, 3, 1, 1};
// Create a HashMap to store the count of each element
Map<Integer, Integer> countMap = new HashMap<>();
// Count the occurrences of each element
for (int num : array) {
if (countMap.containsKey(num)) {
countMap.put(num, countMap.get(num) + 1);
} else {
countMap.put(num, 1);
}
}
// Print the count of each element
System.out.println("Element Count:");
for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}