java如何将所需长度设置为数组中的整数?
如果customerID编号的长度与5位数字不匹配,如何允许用户重新输入该编号
for (int i = 0; i < 5; i++) {
System.out.println("Enter the 5-digit ID number of your customer "
+ (i + 1) + "'s below:");
customerID[i] = myScanner.nextLine();
if (customerID[i].length() != 5) {
// What code goes here. I just want to make it so they can
// re-enter the customerID
}
# 1 楼答案
试试这个。基本上,在获得有效输入之前,不必增加索引
# 2 楼答案
你可以使用你的循环
# 3 楼答案
以下是一种方法:
# 4 楼答案
(可能)最短的解决方案: