现会员注册、要求
-
用户名长度不小于3
-
密码长度不小于6
-
注册时两次输入密码必须相同
private static String userName;
private static String userPwd;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);System.out.println("***欢迎进入注册系统***"); System.out.println(); do { System.out.print("请输入用户名:"); userName = input.next(); System.out.print("请输入密码:"); userPwd = input.next(); if (userName.length() < 3 || userPwd.length() < 6) { System.out.println("用户名长度不能小于3,密码长度不能小于6!"); continue; }else { System.out.println("请再次输入密码:"); String again = input.next(); if (again.equals(userPwd)) { System.out.println("注册成功!请牢记用户名和密码。"); break; }else { System.out.println("两次输入的密码不相同!"); continue; } } }while(true);
}