gpt4 book ai didi

java - 如何将所需的长度设置为数组中的整数?

转载 作者:行者123 更新时间:2023-12-02 00:31:30 27 4
gpt4 key购买 nike

如果客户 ID 号码的长度与 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
}

最佳答案

这是一种方法:

while(true)
{
customerID[i] = myScanner.nextLine();
if(customerID[i].length() == 5) break;
System.out.print("Should be of length 5! Try Again: ");
}

关于java - 如何将所需的长度设置为数组中的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8964181/

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