输入错误java后如何重新启动程序
如果输入了错误的电子邮件地址,我会尝试在某个时间点重新启动程序,这样用户就不必完全重新启动程序,以防他们拼写错误而没有注意到。这就是我目前所拥有的输入错误java后如何重新启动程序,java,Java,如果输入了错误的电子邮件地址,我会尝试在某个时间点重新启动程序,这样用户就不必完全重新启动程序,以防他们拼写错误而没有注意到。这就是我目前所拥有的 public static void main(String[] args) { String grade = JOptionPane.showInputDialog(null, "Please Specify Your Grade"); String First_name = JOptionPane.showInputDialog(
public static void main(String[] args) {
String grade = JOptionPane.showInputDialog(null, "Please Specify Your Grade");
String First_name = JOptionPane.showInputDialog(null, "What is your First Name?");
String Last_name = JOptionPane.showInputDialog(null, "What is your Last Name?");
String message = "You are a " + grade + "\n"
+ "Your Name is " + First_name + " " + Last_name;
JOptionPane.showMessageDialog (null, message);
String email = JOptionPane.showInputDialog (null, "enter email");
if (email.contains("@branfordschools.org")){
JOptionPane.showMessageDialog(null,"Password Accepted");
} else {
JOptionPane.showMessageDialog(null,"Password Incorrect, Program Closing");
System.exit(0);
}
看到java没有GOTO(在出现问题之前,我会一直使用它,这个程序只用于毕业演讲),我该如何让它回到这里
String email = JOptionPane.showInputDialog (null, "enter email");
if (email.contains("@branfordschools.org")){
JOptionPane.showMessageDialog(null,"Password Accepted");
} else {
JOptionPane.showMessageDialog(null,"Password Incorrect, Program Closing");
System.exit(0);
这应该行得通
boolean validInput = false;
while (!validInput) {
String email = JOptionPane.showInputDialog(null, "enter email");
if (email.contains("@branfordschools.org")) {
validInput = true;
JOptionPane.showMessageDialog(null, "Password Accepted");
} else {
JOptionPane.showMessageDialog(null, "Password Incorrect, Program Closing");
}
}
这应该行得通
boolean validInput = false;
while (!validInput) {
String email = JOptionPane.showInputDialog(null, "enter email");
if (email.contains("@branfordschools.org")) {
validInput = true;
JOptionPane.showMessageDialog(null, "Password Accepted");
} else {
JOptionPane.showMessageDialog(null, "Password Incorrect, Program Closing");
}
}
下面是一个简单的while循环,它将继续请求电子邮件,直到它包含“@branfordschools.org”
下面是一个简单的while循环,它将继续请求电子邮件,直到它包含“@branfordschools.org”
使用Do While循环。Google it。基本的东西。你正在寻找的概念叫做循环。换句话说:一些内置的gotos替代品。例如,请参见您可能希望使用endsWith()而不是contains。因为您当前的代码逻辑是greenlight@brandfordschool.orgRANDOMSTUFF,没有问题。使用Do While循环。Google it.Basic stuff。您正在寻找的概念称为循环。换句话说:一些内置的gotos替代品。例如,请参见您可能希望使用endsWith()而不是contains。因为您当前的代码逻辑是greenlight@brandfordschool.orgRANDOMSTUFF,没有问题。