【发布时间】:2021-11-12 04:38:31
【问题描述】:
我有一个创建公司电子邮件域的应用程序,但是在创建循环以运行错误消息以防用户输入无效字符时遇到了一个小问题。
我无法让它与我拥有的东西一起工作,所以我确定我错过了一些重要的东西。
System.out.println("\nEnter name: ");
String name = in.nextLine();
int length = name.length();
for (int x = 0; x < length; x++) {
if(name.substring(x,x+1).equals(".")) {
System.out.println("Error! - name can not contain (.) values\n"
+ "***************************************************");
System.out.println("\nWould you like to capture another name?" +
"\nEnter (1) to continue or any other key to exit");
String opt1 = in.nextLine();
// If statement to run application from the start
if (opt1.equals("1")) {
System.out.println("menu launch");
}
else { System.exit(0); }
}
else { break; }
}
【问题讨论】: