gpt4 book ai didi

java - 试图让程序重复

转载 作者:太空宇宙 更新时间:2023-11-04 06:09:42 27 4
gpt4 key购买 nike

程序检查输入的电子邮件地址是否包含@和.edu如果不是,则需要返回步骤,我想我可以使用 do-while,但我还没有一个可以工作,我如何将 if-else 语句嵌套在 do-while 中?谢谢!

if (UserEmail.contains("@")) {
if (UserEmail.contains(".edu")){
System.out.print("Please create a password: ");
PassWord = kb.nextLine();
System.out.println(UserEmail.replaceAll("@\\S+?\\.edu\\b", ""));
System.out.print("Your password is " + PassWord);
} else {
System.out.print("email is not valid Please, try again.")
} else {
System.out.print("email is not valid Please, try again.");
// at this point it should repeat and ask for the email again
}
}

最佳答案

定义方法 isValid(String email, String password,... some more params) a 并将所有检查逻辑放入该方法中。

写这样的东西

while (!isValid(the params)) {
//ask all the credentials
}

关于java - 试图让程序重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28893897/

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