while (true){
System.out.println("请输入用户名");
String user1 = scanner.nextLine();
String password1 =null;
System.out.println("输入密码");
String password = scanner.nextLine();
System.out.println("请确认密码");
String dpassword = scanner.nextLine();
if(password.equals(dpassword)) password1 = dpassword;
else{
System.out.println("密码不正确");
continue;
}
String phone1 = null;
System.out.println("请输入你的手机号");
String phone = scanner.nextLine();
if((phone.length() == 11) && ((phone.startsWith("13")) || (phone.startsWith("15")) || (phone.startsWith("17"))))
{
phone1 = phone;
}else {
System.out.println("手机号码格式不对");
continue;
}
String birthday1 = null;
System.out.println("请输入生日格式为 :yyyy-mm-dd");
String birthday = scanner.nextLine();
try {
simpleDateFormat.parse(birthday);
birthday1 = birthday;
} catch (ParseException e) {
e.printStackTrace();
continue;
}
String email1 = null;
System.out.println("请输入你的邮箱");
String email = scanner.nextLine();
if(email.contains("@")){
email1 = email;
}else continue;
User u1 = new User(user1,password1,phone1,birthday1,email1);
if(set.size() !=0 ){
int i = 0;
System.out.println();
for(User us:set) {
if (us.equals(u1)) {
System.out.println("已经有该用户,不可重复注册");
continue;
}
i++;
}
if(i == set.size()) set.add(u1);
}else set.add(u1);
int a = -1;
System.out.println("你输入0 或者非0的数字 0:停止注册用户信息显示用户信息,非0继续执行 ");
a = scanner.nextInt();
if(a == 0) break;
else continue;
}
为啥我输入非0数字开始第二次循环的时候,不能输入用户名,
但是手机号或者其他输错格式 导致的再一次循环就可以输入用户名。这是这么原因?