gpt4 book ai didi

Java 字符串以逗号分割

转载 作者:行者123 更新时间:2023-12-01 06:18:17 24 4
gpt4 key购买 nike

我在下面有这段代码,它给了我这个输出

1,2,3,4,3,4,5,4,3,5,3,4,5,5,4,64,
[Ljava.lang.String;@3e25a5
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f
[I@19821f

input.txt文件包含1,2,3,4,3,4,5,4,3,5,3,4,5,5,4,64,

代码是这样的。很明显在拆分时有一个简单的错误,但我发现很难找到什么。

public static void main(String[] args) {
// TODO Auto-generated method stub



try{
FileInputStream fstream = new FileInputStream("input.txt");
DataInputStream dat = new DataInputStream (fstream);
BufferedReader in = new BufferedReader(new InputStreamReader(dat));
String[] str ;

int arr[] = new int [100];


String line;

while ((line = in.readLine()) != null)
{

System.out.println(line);
str = line.split(",");
System.out.println(str);

for(int i = 0 ;i<str.length ; i++)
{
arr[i]= Integer.parseInt(str[i]);
System.out.println(arr);
}
}

fstream.close();

}

catch(IOException e)
{
System.out.print(e);
}


}

最佳答案

改变这个

   System.out.println(arr);

   System.out.println(arr[i]);

在打印数组 arr 之前,而不是数组的元素。

关于Java 字符串以逗号分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5953091/

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