Lecture Notes on 5 Oct 2011 String s = "Humpty Dumpty sat on a wall"; // traverse a string for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); System.out.println (ch); } // this method checks if a string has 6 to 10 characters // and has at least 1 digit, 1 lower case and 1 upper case letter public static boolean isValid (String s) { if ((s.length() < 6) || (s.length() > 10)) { return false; } boolean isDigit = false; boolean isLowerCase = false; boolean isUpperCase = false; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if ((!isDigit) && (ch >= '0') && (ch <= '9')) { isDigit = true; } if ((!isLowerCase) && (ch >= 'a') && (ch <= 'z')) { isLowerCase = true; } if ((!isUpperCase) && (ch >= 'A') && (ch <= 'Z')) { isUpperCase = true; } } return (isDigit) && (isLowerCase) && (isUpperCase); }