我有一个正确运行的代码,但它没有显示任何输出

时间:2016-02-05 07:00:07

标签: java

我的代码中没有错误,但不知道为什么没有输出可见。

代码是对句子中的单词进行排序,例如"你好吗"看起来喜欢"嗨你好吗"。

public static void main(String args[]) {

    @SuppressWarnings("resource")
    Scanner scan = new Scanner(System.in);

    int n = Integer.parseInt(scan.nextLine());

    ArrayList<String> lines = new ArrayList<String>();
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> words_2 = new ArrayList<String>();
    boolean once_entered = true;
    for (int i = 0; i < n; i++) {
        lines.add(i, scan.nextLine() + " ");
    }
    for (int i = 0; i < n; i++) {

         String word = "";
        for (int j = 0; j < lines.get(i).length(); j++) {
            char char_0 = lines.get(i).toLowerCase().charAt(j);
            if ((int) (char_0) >= (int) ('a') && (int) (char_0) <= (int) ('z')) {
                word += char_0;
             once_entered = false;
            } else if (!once_entered) {
                words.add(word);
                word = "";
                once_entered = true;
            }
        }
    }
    for (int i = 0; i < words.size(); i++) {
        boolean contains =false;
        for(int j=0;j<words_2.size();j++){
            if(words_2.get(j).contentEquals(words.get(i)))
                contains=true;
        }
        if(!contains)
            words_2.add(words.get(i));
    }
    Collections.sort(words_2);
    System.out.println(words_2.size());
    for (int i = 0; i < words_2.size(); i++) {
        System.out.println(words_2.get(i));

    }
}

0 个答案:

没有答案