package LESSON8; import java.util.*; public class exercise2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入用户名:"); String username=sc.nextLine().trim();//去掉空格 if (username.length()>=6) { char[] c=username.toCharArray(); boolean bo1=false; boolean bo2=false; for (int i = 0; i < c.length; i++) { if(Character.isDigit(c[i])){ bo1=true; } if(Character.isLetter(c[i])){ bo2=true; } } if(bo1&&bo2){ System.out.println("用户名注册成功, 用户名为:"+username); } else{ System.out.println("用户名必须包含字母和数字"); } // label:for (int i = 0; i < c.length; i++) { // if(Character.isDigit(c[i])) // { // for (int j = 0; j < c.length; j++) // { // if(Character.isLetter(c[j])) // { // System.out.println("用户名合法"); // System.out.println("用户名为:"+username); // break label; // } // else // { // System.out.println("用户名不包含字母"); // break label; // } // } // } // if(i==c.length-1){ // System.out.println("用户名不包含数字"); // } // } // } // // } else{ System.out.println("用户名长度不能小于6位"); } System.out.println("请输入密码"); Scanner sc2=new Scanner(System.in); boolean bo3=false; boolean bo4=false; boolean bo5=false; String password=sc2.nextLine().trim(); if(password.length()>=8) { for (int i = 0; i < password.length(); i++) { if(Character.isDigit(password.charAt(i))) { bo3=true; } if(Character.isLetter(password.charAt(i))) { bo4=true; } } if(password.contains("_")||password.contains("$")){ bo5=true; } if(bo3&&bo4&&bo5) { System.out.println("密码注册成功,密码为:"+password); } else{ System.out.println("密码必须包含特殊符合_或者$,英文字母以及数字"); } } else { System.out.println("密码长度必须大于8"); } } }