I've just solved this problem and I hope you guys give me any feedback to make my code be better.
Problem: There are N strings. Each string's length is no more than 20 characters. There are also Q queries. For each query, you are given a string, and you need to find out how many times this string occurred previously.
Input Format
The first line contains N, the number of strings. The next N lines each contain a string. The N + 2nd line contains Q, the number of queries. The following Q lines each contain a query string.
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String[] stringArr = new String[n];
for (int i = 0; i < n; i++){
stringArr[i] = scan.next();
}
int q = scan.nextInt();
for (int i = 0; i < q; i++){
String stringQue = scan.next();
int occNum = 0;
for (int j = 0; j < n; j++){
if (stringQue.equals(stringArr[j])) occNum++;
}
System.out.println(occNum);
}
}
}