Print Mode

Report a typo

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.

Sample Input 1:

11
1 2 3 4 5 5 5 6 7 8 9

Sample Output 1:

5 3
Write 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);
}
}
___

Create a free account to access the full topic