配列を使用して、テキスト ファイル内で繰り返される単語をカウントするにはどうすればよいですか?
私のプログラムはファイル内の単語の総数を出力できますが、プログラムに異なる単語の数を出力させ、次のように繰り返される単語の数のリストを出力させるにはどうすればよいですか。
ケーキ: 4 a: 320 ピース: 2 の 24
(大文字と小文字の単語は同じ単語と見なされます)
void FileReader() {
System.out.println("Oppgave A");
int totalWords = 0;
int uniqueWords = 0;
String [] word = new String[35000];
String [] wordC = new String [3500];
try {
File fr = new File("Alice.txt");
Scanner sc = new Scanner (fr);
while(sc.hasNext()){
String words = sc.next();
String[] space = words.split(" ");
String[] comma = words.split(",");
totalWords++;
}
System.out.println("Antall ord som er lest er: " + totalWords);
} catch (Exception e) {
System.out.println("File not found");
}