例如 if (NUM4>-1) { System.out.println("您的语句中有无效字符,请重试。"); EMAIL = UI.nextLine(); "return to line '#'" } 我需要有一种方法可以返回到特定的代码行,而不是用 .break 结束程序
编辑好吧,到目前为止,这是我的代码。
package cormier.email.checker;
import java.util.Scanner;
import java.lang.String;
public class CormierEmailChecker {
/*
*/
public static void main(String[] args) {
Scanner UI = new Scanner(System.in);
String EMAIL, EMAILSPACE, EMAILCHECK1;
int NUM1,NUM2,NUM3,NUM4,test;
System.out.println("Please enter your E-Mail address.");
EMAIL = UI.nextLine();
NUM1 = EMAIL.indexOf("@");
NUM2 = EMAIL.indexOf("#");
NUM3 = EMAIL.indexOf("!");
NUM4 = EMAIL.indexOf(" ");
test = 0;
while(test == 0){
test=1;
if (NUM4>-1) {
System.out.println("Invalid character in E-Mail address, please try again.");
EMAIL = UI.nextLine();
NUM4 = EMAIL.indexOf(" ");
test=0;
}
else if(NUM1==-1) {
System.out.println("E-Mail address is missing an '@' symbol");
EMAIL = UI.nextLine();
NUM1 = EMAIL.indexOf("@");
test=0;
}
else if(NUM1==0) {
System.out.println("E-Mail shouldn't start with an '@' symbol");
EMAIL = UI.nextLine();
NUM1 = EMAIL.indexOf("@");
test=0;
}
else if(NUM2>-1) {
EMAIL = UI.nextLine();
NUM2 = EMAIL.indexOf("#");
test=0;
}
else if(NUM3>-1) {
System.out.println("Invalid character in E-Mail address, please try again.");
EMAIL = UI.nextLine();
NUM3 = EMAIL.indexOf("!");
test = 0;
}
}
if(EMAIL.endsWith(".ca") || EMAIL.endsWith(".com")) {
}
else {
System.out.println("Please restart program");
}
}
}