44 lines
864 B
Java
44 lines
864 B
Java
|
import java.util.Scanner;
|
||
|
|
||
|
public class LabProgram {
|
||
|
|
||
|
public static int getFrequencyOfWord(String[] wordsList,
|
||
|
int listSize, String currWord){
|
||
|
int frequency = 0;
|
||
|
for (int i=0; i<listSize;i++){
|
||
|
if (wordsList[i].equals(currWord)){
|
||
|
frequency +=1;
|
||
|
}
|
||
|
}
|
||
|
return frequency;
|
||
|
|
||
|
|
||
|
}
|
||
|
public static void main(String[] args) {
|
||
|
/* Type your code here. */
|
||
|
|
||
|
Scanner scnr = new Scanner(System.in);
|
||
|
|
||
|
int numOfWords;
|
||
|
int i;
|
||
|
|
||
|
String[] listOfWords = new String[20];
|
||
|
int[] frequency = new int[20];
|
||
|
|
||
|
numOfWords = scnr.nextInt();
|
||
|
|
||
|
for (i=0; i<numOfWords;i++){
|
||
|
listOfWords[i] = scnr.next();
|
||
|
}
|
||
|
|
||
|
for (i=0; i<numOfWords;i++){
|
||
|
frequency[i] = getFrequencyOfWord(listOfWords, numOfWords, listOfWords[i]);
|
||
|
}
|
||
|
|
||
|
for (i=0; i<numOfWords;i++){
|
||
|
System.out.println(listOfWords[i] + " " + frequency[i]);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|