public class CheckPassword { public String rule1(String pw){ if( pw.length() < 6 || pw.length() > 15) return "1"; return ""; } // I combined rue 2 and 3 together. public String rule23(String pw){ if(pw.length() == 0) return ""; int ccount=0; int dcount = 0; for(int i=0;i=65 && c <=90) ccount++; else if(c >=97 && c <=122) ccount++; else if(c >=48 && c<=57) dcount++; } if(dcount == 0) return "2"; if(ccount ==0) return "3"; return ""; } public String rule4(String pw){ if(pw.endsWith("99")){ String s = rule23(pw.substring(0,pw.length() -2)); if(s.equals("2")) return "4"; } return ""; } public String checkPassword(String pw){ String ret1 = rule1(pw); String ret2= rule23(pw); String ret3 = rule4(pw); String res = ""; if(!ret1.equals("")) res = ret1; if(!ret2.equals("")) res += "," + ret2; if(!ret3.equals("")) res+="," + ret3; if(res.equals("")) return "valid password"; else return "not a valid password (rule(s) " + res + " violated"; } public static void main(String[] args){ String[] str = {"NPC2006","CGI","a199","99","CGI99"}; CheckPassword cp = new CheckPassword(); for(int i=0;i