1

単語、特定の文字列、文を数える簡単なプログラムを作成しようとしています。私は単語カウンターを持っており、特定の文字列を数えるカウンターを持っていますが、基本的にすべての小数を数えると「.」が複数ある場合はどうなるのか、文を数える方法がわかりません。

これまでのところ、これは私のコードです..

int count = 0;
// while there is something in the file, keep reading and counting
while (inputFile.hasNext()) {
   String token = inputFile.next();
   count++;
}

int letters = 0;
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
    String nextToken = scanner.next();
    if (nextToken.equalsIgnoreCase("for"))
    {
    letters++;
    }

}
4

1 に答える 1