gpt4 book ai didi

java - 尝试将用户输入与文本文件进行比较,然后在java上读取该点的数字值

转载 作者:行者123 更新时间:2023-12-02 04:09:49 25 4
gpt4 key购买 nike

while(inFile.hasNext())
{
String Desnation = inFile.next();

if(givenLocation.equalsIgnoreCase(Desnation))
{
int num1 = inFile.nextLine();
int num2 = inFile.nextLine();

System.out.println("Yay!");
}
}

它说它无法将字符串转换为 int,因此尝试事先解析它,但子字符串没有注册用户的输入。

最佳答案

您必须将字符串转换为整数:

try {
int num1 = Integer.parseInt(inFile.nextLine());
int num2 = Integer.parseInt(inFile.nextLine());
} catch(NumberFormatException e) {
//handle exception, ex print some text
}

顺便说一句,为 Java naming convention说:

Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

考虑改变 国家至

desnation

关于java - 尝试将用户输入与文本文件进行比较,然后在java上读取该点的数字值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33903517/

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