-2

私はtxtファイルからコンコーダンスを印刷しようとしています.スキャナを使用して以下のファイルを読み込んでいます.単語を配列リストに入れるのに問題があるようです.

public class Concordance 
{
    public static void main (String[]args) throws IOException 
    {
        TreeMap <String, ArrayList<Integer>> concordance = new TreeMap <String, ArrayList<Integer>>();
        File myfile = new File ("Caesar.txt");
        Scanner scan = new Scanner(myfile);
        ArrayList <Integer > integer = new ArrayList <Integer>();
        for (int i = 0; i < scan.nextLine().length(); i++) 
        {
            String key = scan.nextLine().toLowerCase();
            if (scan.nextLine().length(i) > 1) 
            {
                if (concordance.get(key) == null) {
                    concordance.put(key, 1))
                } else {
                    ArrayList<Integer> value = concordance.get(key).indexOf(integer);
                    value++;
                    concordance.put(key, value);
                }
            }
        }
        System.out.println(concordance);
    }
}
4

1 に答える 1

0

このコードはコンパイルできません。

に整数を入れようとしていMap<String, ArrayList<String>>ます。

これは行です:

concordance.put(key, 1))

また、この行は失敗します:

value++;

value は のコレクションでIntegerあるため、整数ではありません。

この行は、実行時に常に false を返します。

ArrayList<Integer> value = concordance.get(key).indexOf(integer);

integerは として宣言されているためArrayList、Integer のコレクションを検索しています。

一般に、 と の間に大きな混乱がIntegerありArrayList<Integer>ます。scan.nextLine()また、呼び出されるたびに回線が進むことに気付かずに呼び出しを行っています。

于 2011-11-10T09:31:04.307 に答える