1 import java.util.Scanner; 2 /** 3 * @author 冰樱梦 4 * 时间:2018年下半年 5 * 题目:检测密码 6 * 7 */ 8 public class Exercise06_18 { 9 public static void main(String[] args){ 10 Scanner input = new Scanner(System.in); 11 System.out.println("输入密码: "); 12 String passWord=input.nextLine(); 13 checkString(passWord); 14 } 15 public static void checkString(String password){ 16 int sum=0,s=0; 17 if((password.length()>=8)){ 18 for(int i=0;i<password.length();i++){ 19 if((('a'<=password.charAt(i))&&(password.charAt(i)<='z')) || (('A'<=password.charAt(i))&&(password.charAt(i)<='Z')) || (('0'<=password.charAt(i))&&(password.charAt(i)<='9'))){ 20 s++; 21 if(('0'<=password.charAt(i))&&(password.charAt(i)<='9')) sum++; 22 } 23 else System.out.println("Invalid Password"); 24 } 25 if((s==password.length())&&(sum>=2)) System.out.println("Valid Password"); 26 } 27 else System.out.println("Invalid Password"); 28 } 29 }