Given a list of integers of length n, write a program that uses a HashMap to find the mode (the most frequently occurring element) in the list. The program must print the mode and its frequency separated by a space.
Introduction to HashMap
Print Mode
Report a typo
Sample Input 1:
11
1 2 3 4 5 5 5 6 7 8 9Sample Output 1:
5 3Write a program in Java 17
import java.util.HashMap;
import java.util.Scanner;
class Main {
private static void printMode( int[] map) {
// Enter your Code Here
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] map = new int [n];
for (int i = 0; i < n; ++i) {
map[i] = scanner.nextInt();
}
printMode(map);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.