school/old/java1/word-frequencies/LabProgram.java
2021-01-20 06:57:22 -05:00

41 lines
844 B
Java

/* Joseph Green
* 07-Oct-2020
*
* Read int that indicates list of words to follow
* Read in that many of words
* assume list will always contain less than 20 words
*/
import java.util.Scanner;
public class LabProgram {
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++){
for (int j=0; j<numOfWords;j++){
if (listOfWords[i].equals(listOfWords[j])){
frequency[i] +=1;
}
}
}
for (i=0; i<numOfWords;i++){
System.out.println(listOfWords[i] + " " + frequency[i]);
}
}
}