gpt4 book ai didi

java - 为什么当我询问这个​​词出现了多少次时,我总是得到 138

转载 作者:行者123 更新时间:2023-12-01 18:16:08 25 4
gpt4 key购买 nike

我试图找出某个状态在一列 csv 文件中出现的次数。它还只打印一半的州。我的代码如下

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;

public class csvtxt {

public static void main(String a[]){
StringBuilder sb = new StringBuilder();
String strLine = "";
List<String> list = new ArrayList<String>();
try {
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\dbb38\\Downloads\\customers_export_111 - customers_export_1 (1).csv"));
while (strLine != null)
{
strLine = br.readLine();
sb.append(strLine);
sb.append(System.lineSeparator());
strLine = br.readLine();
if (strLine==null)
break;
list.add(strLine);
}
//
String wordToSearchFor = "Alabama";
int Alabama = 0;
for(String Alabama1 : list)
{
if(Alabama1.equals(wordToSearchFor))
{
Alabama++;
}
}
System.out.println("Alabama = " + "["+ Alabama +"]");
//
String wordToSearchFor1 = "Alaska";
int Alaska = 0;
for(String Alaska1 : list)
{
if(Alaska1.equals(wordToSearchFor))
{
Alaska++;
}
}
System.out.println("Alaska = " + "["+ Alaska +"]");
//
String wordToSearchFor2 = "Arizona";
int Arizona = 0;
for(String Arizona1 : list)
{
if(Arizona1.equals(wordToSearchFor))
{
Arizona++;
}
}
System.out.println("Arizona = " + "["+ Arizona +"]");
//
System.out.println(Arrays.toString(list.toArray()));
br.close();
} catch (FileNotFoundException e) {
System.err.println("File not found");
} catch (IOException e) {
System.err.println("Unable to read the file.");
}
}
}

这是我得到的输出。我切断了一些输出,因为 95881 字符太多。

Alabama = [138]
Alaska = [138]
Arizona = [138]
[ South Dakota, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia]

佛蒙特州应该有 35 个,但它只打印了其中的 17 个。任何帮助将不胜感激!a

最佳答案

替换

if(Arizona1.equals(wordToSearchFor)) 

if(Arizona1.equals(wordToSearchFor2)) 

您也需要对其他人进行类似的更改。看到你的错误了吗?

关于java - 为什么当我询问这个​​词出现了多少次时,我总是得到 138,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60364359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com