java 输入密码_Java 写一个输入密码的小程序

已完成,复制粘贴即可。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);}}}

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值