its been 6 hours since I have been writing the code but to no avail, I don\'t no where I am making the mistake but I am making some. Its a frequency output program and output sh
/**
* The methods counts the frequency of each element in an array.
*
* Approach: The method checks if the element is already present in the Map of frequency.
* If it is not present, add it to the map with the frequency 1 else put it in the map with
* an increment by one of it's existing frequency.
*
* @param arr list of elements
* @return frequency of each elements
*/
public static Map countFrequency(int[] arr) {
Map frequency= new HashMap();
for(int i = 0; i < arr.length; i++) {
if(frequency.get(arr[i])==null) {
frequency.put(arr[i], 1);
}
else {
frequency.put(arr[i],frequency.get(arr[i])+1);
}
}
System.out.println("\nMap: "+frequency);
return frequency;
}