有没有一个函数可以用来在if语句中挑选java中的一系列大数字



我正在尝试创建一个人力资源数据库,我想选择一系列数字,这些数字应该显示员工在达到60岁时应该退休

String Age = jtxtAge.getText();
if (Age.matches("^[0-59]*$")) {
JOptionPane.showMessageDialog(null, "Valid");
}
else {
jtxtAge.setBackground(Color.red);
JOptionPane.showMessageDialog(null, "Due for retirement");
return;
}

matches函数只允许我选择一个数字的第一个索引,所以26岁的人仍然会显示"到期退休"。

使用parseInt((方法将输入年龄转换为整数。

String Age = jtxtAge.getText();
int age=Integer.parseInt(Age);
if(age>=0&&age<=59)) {
JOptionPane.showMessageDialog(null, "Valid");
} else {
jtxtAge.setBackground(Color.red);
JOptionPane.showMessageDialog(null, "Due for retirement");
return;
}

最新更新