作者:平和-3699 | 来源:互联网 | 2023-08-30 11:39
Greetings,Imtryingtovalidatewhethermyintegerisnull.Ifitis,Ineedtoprompttheusert
Greetings,
I'm trying to validate whether my integer is null. If it is, I need to prompt the user to enter a value. My background is Perl, so my first attempt looks like this:
我正在尝试验证我的整数是否为空。如果是,我需要提示用户输入值。我的背景是Perl,所以我的第一次尝试看起来像这样:
int startIn = Integer.parseInt (startField.getText());
if (startIn) {
JOptionPane.showMessageDialog(null,
"You must enter a number between 0-16.","Input Error",
JOptionPane.ERROR_MESSAGE);
}
This does not work, since Java is expecting boolean logic.
这不起作用,因为Java期望布尔逻辑。
In Perl, I can use "exists" to check whether hash/array elements contain data with:
在Perl中,我可以使用“exists”来检查散列/数组元素是否包含以下数据:
@items = ("one", "two", "three");
#@items = ();
if (exists($items[0])) {
print "Something in \@items.\n";
}
else {
print "Nothing in \@items!\n";
}
Is there a way to this in Java? Thank you for your help!
在Java中有这种方法吗?谢谢您的帮助!
Jeremiah
P.S. Perl exists info.
附: Perl存在信息。
7 个解决方案