public class MyClass {
private static void mostFrequentWord(String[] words) {
int frequency = 0;
int size = words.length;
String frequent_word = "";
for (int i = 0; i < size; i++) {
int count = 1;
for (int j = i + 1; j < size; j++) {
if (words[j].equals(words[i])) {
count++;
}
}
if (count >= frequency) {
frequent_word = words[i];
frequency = count;
}
}
System.out.println(frequent_word + ": " + frequency + " times");
}
public static void main(String args[]) {
String[] arr = {"java", "c++", "c", "c#", "c", "go", "php", "java", "java", "c", "python", "php", "c"};
mostFrequentWord(arr);
}
}
/*
run:
c: 4 times
*/