gpt4 book ai didi

java - 引用一个方法并检查Input

转载 作者:行者123 更新时间:2023-11-30 07:12:19 25 4
gpt4 key购买 nike

我创建了一个方法来检查输入是否在 csv 文件中的列大小之间。

 public static boolean isValidNumber(String uInput) {

Long convert = Long.parselong (uInput);
int convert2 = (int) convert;// Need to do this because of the JOptionPane
if(colmn.length > convert) {
System.out.println("The Column exists.");
}
else { System.out.println("The Column doesn't exists.");}

return true; }}

ma​​in方法中,我引用了isValidNumber-Method

 // some previous code

do { String userInput = JOptionPane.showInputDialog);
} while(isValidNumber(userInput));}


//next code

所以即使用户输入正确并且存在于 csv 文件中,我也无法退出循环。有人可以帮我吗?

最佳答案

您的 isValidNumber 始终返回 true,这就是您无法跳出循环的原因。

尝试使用以下--

public static boolean isValidNumber(String uInput) {

Long convert = Long.parselong (uInput);
int convert2 = (int) convert;// Need to do this because of the JOptionPane
if(colmn.length > convert) {
System.out.println("The Column exists.");
return true;
}
else { System.out.println("The Column doesn't exists."); return false;}

}

关于java - 引用一个方法并检查Input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39032428/

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