package com.javabin.interface_;
/**
* Copyright (C), 2018-2021, Mr.Lin
* Author: Mr.Lin
* Date: 2021/11/20 1:11
* FileName: Holloweork01
* Description:
*/
public class Holloweork01 {
public static void main(String[] args) {
String name = "冯清河";
String pwd = "1314520";
String email = "5644@qq.4644";
try {
userRegister(name, pwd, email);
System.out.println("恭喜注册成功!!!");
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static void userRegister(String name, String pwd, String email) {
if (!(name != null && pwd != null && email != null)) {
throw new RuntimeException("输入的字符不允许为空值;");
}
int userLength = name.length();
if (!(userLength >= 2 && userLength <= 4)) {
throw new RuntimeException("用户名长度要求2~4;");
}
if (!(pwd.length() == 7 && isDigital(pwd))) {
throw new RuntimeException("密码长度要求长度7,密码要求位数字;");
}
int i = email.indexOf("@");
int j = email.indexOf(".");
if (!(i > 0 && j > i)) {
throw new RuntimeException("邮箱必须包含@和. 并且.必须在@之后;");
}
}
public static boolean isDigital(String str) {
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
if (chars[i] < '0' && chars[i] > '9') {
return false;
}
}
return true;
}
}