java统计单词个数怎么使用map



```java
import java.util.Scanner;

public class Main{
    static int p;//行数
    static int k;//部分
    static String S;//字符串
    static int wordSize;
    static String word[];
    static int num = 0;
    static int cut;//分割

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        p = sc.nextInt();
        k = sc.nextInt();
        S = sc.nextLine();
        S = "";
        for(int i=0;i<p;i++){
            S = S + sc.nextLine();
        }
        wordSize = sc.nextInt();
        word = new String[wordSize];
        for(int j=0;j<wordSize;j++){
            word[j] = sc.next();
        }
        wordCount(S);
        if(cut<k) {
            num = num-(k-1);
        }
        System.out.println(num);
    }

    public static void wordCount(String S){
        for(int i=0;i<S.length();i++) {
            for(int j=0;j<wordSize;j++) {
                if(S.substring(i,S.length()).length()<word[j].length()) {
                    continue;
                }
                if(S.substring(i,i+word[j].length()).length()<word[j].length()){
                    continue;
                }
                if(S.substring(i,i+word[j].length()).equals(word[j])) {
                    //System.out.println(S+":"+word[j]);
                    num++;
                    //System.out.println("第"+num);
                    if(i!=0) {
                        cut++;
                        //System.out.println("分割:"+cut);
                    }
                    wordCount(S.substring(i+1,S.length()));
                    return;
                }
            }
        }
    }
}

```

你的代码对吗?原始问题是什么?我现在不知道你的原始目的怎么帮你看代码