已完成,复制粘贴即可。import java.util.Scanner;public class YuGiOh{private static void checkPass ( String password ){String regp = ".*[A-Z].*";String rego = ".*[a-z].*";String regq = ".*\\d.*";String regs = ".*[\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\;\\:\\,\\.\\\\/\\?].*";String regex = "^[a-zA-Z\\d\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\;\\:\\,\\.\\\\/\\?]{6,}$";String result = "";if (password.length () < 6){result += "\t\t-contain at least six characters. Your password is only " + password.length () + " characters long.\n";}if (!password.matches (regp)){result += "\t\t-contain at least one uppercase letter.\n";}if (!password.matches (rego)){result += "\t\t-contain at least one lowercase letter.\n";}if (!password.matches (regq)){result += "\t\t-contain at least one number.\n";}if (!password.matches (regs)){result += "\t\t-contain at least one of the following special characters:`!@#$%^&*()_+=[{}];:,.<>/?\n";}else if (!password.matches (regex)){result += "\t\t-not contain an invalid character. The valid special characters:`!@#$%^&*()_+=[{}];:,.<>/?\n";}if (!"".equals (result)){System.out.println ("Your password must:\n" + result);}else{System.out.println ("Your valid password is: " + password);}System.out.println ();}public static void main ( String[] args ){Scanner scanner = new Scanner (System.in);while (true){System.out.print ("Enter a valid password: ");String password = scanner.nextLine ();checkPass (password);}}}
取消
评论