这段代码有什么问题吗,为什么会报Compilation error?

tkz4869kenan edited 2 年,8 月前

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    static Scanner scanner;
    static boolean debug=false;
    static HashSet keywords = new HashSet();
    static {
        keywords.add("the");
        keywords.add("a");
        keywords.add("an");
        keywords.add("of");
        keywords.add("for");
        keywords.add("and");
    }
    //input
    static int T;
    static int cas = 0;
    String sentence;

    //output
    int count=0;

    void read(){
        sentence=scanner.nextLine();
    }
    void calc(){
        String[] words = sentence.split("\\s+");
        for(String word: words){
            if(!keywords.contains(word)){
                count++;
            }
        }
    }
    void output(){
        System.out.println("case#"+cas+":");
        System.out.println(count);
    }

    public static void main(String[] args) throws FileNotFoundException {
        scanner=new Scanner(System.in);
        if(debug)
            scanner=new Scanner(new File("in-EOJ2974.txt"));
        T = scanner.nextInt();
        scanner.nextLine();
        while (T-- > 0) {
            EOJ2974 obj = new EOJ2974();
            obj.read();
            obj.calc();
            obj.output();
            cas++;
        }
    }

}

Comments