Multiple Occurence

Report a typo

Write a Java program that accepts a list of words from the user and stores them in a HashMap. The program must then print out the word that occurs the most and the frequency of that word in the list.

Sample Input 1:

the cat sat on the mat

Sample Output 1:

the 2
Write a program in Java 17
import java.util.HashMap;
import java.util.Scanner;

class Main {
private static void printMostFrequentWord(String[] words) {
// write your code here
}

// don't change the code below
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] words = scanner.nextLine().split(" ");
printMostFrequentWord(words);
}
}
___

Create a free account to access the full topic