【发布时间】:2020-06-15 09:18:14
【问题描述】:
嘿,刚刚为学校做一个项目,想知道如何限制用户只能输入 4 整数输入作为邮政编码。例如:(1454)
while (count == 1)
{
System.out.println("Input a postcode for us to send you the package: ");
try
{
postage = in.nextInt();
}
catch (Exception e)
{
System.out.println("This is an invalid input!");
in.next();
continue;
}
if (postage >= 0000 && postage <= 9999)
{
System.out.println(" ");
}
}
【问题讨论】:
-
你应该阅读输入,如果太长,再问一遍?
标签: java validation input integer