// 实现会员注册
// 对用户名长度进行限制
// 对密码长度进行限制
// 注册时两次输入密码必须相同
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Registered test = new Registered();
test.registered();
}
}
class Registered {
private String username;
private String password;
void registered() {
Scanner in = new Scanner(System.in);
boolean judge = false;
do {
System.out.print("请输入用户名:");
String tempName = in.next();
if (tempName.length() < 4) {
System.out.println("请重新设定用户名,长度需大于3个字符");
} else {
username = tempName;
judge = true;
}
} while (!judge);
boolean judgePass = false;
do {
System.out.println("请输入您要设置的密码:");
String tempPassword = in.next();
if (tempPassword.length() < 7) {
System.out.println("请重新设定密码,密码长度需大于6个字符。");
} else {
System.out.println("请再次输入您刚刚设定的密码:");
String cheakPassword = in.next();
if (cheakPassword.equals(tempPassword)) {
password = cheakPassword;
judgePass = true;
} else {
System.out.println("两次输入的密码不一致,请检查后重新输入.");
}
}
} while (!judgePass);
System.out.println("注册成功,以下为你的个人信息:");
System.out.println("Registered{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
'}');
}
}
.
最新推荐文章于 2022-08-24 10:33:02 发布