gpt4 book ai didi

java - 将 String 转换为 int

转载 作者:行者123 更新时间:2023-12-01 14:38:36 29 4
gpt4 key购买 nike

我有一个从文件中读取的字符串对象数组。我需要将其中一些字符串用作整数。我编写了一个方法来读取文件,但现在我只是不知道如何从文件中获取数字,这是文件

29,,
Chute,1,0
Chute,2,0
Chute,3,0
Chute,4,0
Chute,5,0
Chute,6,0
Chute,7,0
Chute,8,0
Chute,9,0
Chute,0,1
Chute,0,2
Chute,0,3
Chute,9,1
Chute,9,2
Chute,9,3
Ladder,0,5
Ladder,1,5
Ladder,2,5
Ladder,3,5
Ladder,4,5
Ladder,5,5
Ladder,6,5
Ladder,7,5
Ladder,8,5
Ladder,9,5
Ladder,9,6

这是我的方法

public void readBoard(String file)throws FileNotFoundException
{
File clboard = new File ("myBoard.csv");
Scanner x = new Scanner(clboard);
while(x.hasNext())
{
String c = x.nextLine();
String [] myboard =c.split(",");
}
}

最佳答案

尝试

int numOne = Integer.parseInt(myboard[1]);
int numTwo = Integer.parseInt(myboard[2]);

紧接在split行之后。

关于java - 将 String 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16225439/

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