我正在尝试制作一个简单的程序来计算单词、某些字符串和句子。我有计数器这个词,我有一个计数器来计算某些字符串,但是,我不知道如何计算句子,因为基本上如果我计算所有小数,如果有多个“.”。
到目前为止,这是我的代码..
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++;
}
}