public class Test { public static void main(String[] args) { String name = "qqq"; String password = "123456"; String email = "qqq@souhu.com"; try { Method(name, password, email); System.out.println("注册成功!"); } catch (Exception e) { System.out.println(e.getMessage()); } } public static void Method(String name, String password, String email) { if (!(2 <= name.length() && name.length() <= 4)) { throw new RuntimeException("用户名输入不正确!"); } if (!((password.length() == 6) && (isDigital(password)))) { throw new RuntimeException("密码不正确!"); } int i1 = email.indexOf("@"); int i2 = email.indexOf('.'); if (!(i1 > -1 && i2 > i1)) { throw new RuntimeException("邮箱格式不正确!"); } } @SuppressWarnings({"all"}) 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; } }
11-30
336
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-18
4060
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)