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");
}
}