import java.util.*;
import java.lang.*;
import java.io.*;
// The main method must be in a class named "Main".
class Main {
public static void main(String[] args) {
int[] A = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
// Create a HashMap to store the frequency of elements.
// Key: Array Element (INTEGER) Value: Frequency (INTEGER)
HashMap<Integer, Integer> freqmap = new HashMap<>();
// Iterate through the array 'A' to calculate the frequency of each element.
for (int i = 0; i < A.length; i++) {
int element = A[i];
// If the element is already present in the Frequency Map, increment its old frequency.
if (freqmap.containsKey(element)) {
int oldFrequency = freqmap.get(element);
freqmap.put(element, oldFrequency + 1);
}
// If the element is not present in the Frequency Map, add it with a frequency of 1.
else {
freqmap.put(element, 1);
}
}
// Print the frequency map using a basic loop.
for (Integer key : freqmap.keySet()) {
Integer frequency = freqmap.get(key);
System.out.println("Element " + key + ": Frequency " + frequency);
}
}
}
To embed this project on your website, copy the following code and paste it into your website's HTML: