我正在尝试计算主题标签在 CSV 文件中出现的次数。问题是,我跳过了每一列的最后一行,而不是计算 75 个东西,它只计算 70 个。这是代码,抱歉,我是 Java 新手,它可能很简单,但我想不通出去。
import java.util.Scanner;
import java.io.File;
public class HashtagCounter {
public static void main(String[] args) throws Exception {
int total = 0;
int count = 0;
File file = new File("hashtags.csv");
Scanner input = new Scanner(System.in);
Scanner scan = new Scanner(file).useDelimiter(",\\s*");
System.out.println("Please enter a hashtag");
String keyboard = input.nextLine();
while(scan.hasNext()){
//System.out.println(scan.next());
total = total + 1;
if(scan.next().equals(keyboard)){
count = count + 1;
}
}
System.out.println("The hashtag " + keyboard + " appears " + count + " time(s), out of a total of " + total + " entries");
}
}