import java.util.Scanner; /** * @author Md. Abdullah Ibna Harun * */ public class App { private static Scanner sc = new Scanner(System.in); static class Helper { public static int digitCount(String str) { int digits = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) >= 48 && str.charAt(i) <= 57) { digits++; } } return digits; } public static boolean alphabateChecks(String str) { if (str == null || str.equals("")) { return false; } for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ((!(ch >= 'A' && ch <= 'Z')) && (!(ch >= 'a' && ch <= 'z')) && (!(str.charAt(i) >= 48 && str.charAt(i) <= 57))) { return false; } } return true; } } public static void main(String[] args) { System.out.print("Input Password : "); String password = sc.nextLine(); if (password.length() <= 10) { // 1st condition if (Helper.alphabateChecks(password)) { // 2nd condition if ((Helper.digitCount(password) >= 2)) { // 3rd condition System.out.println("Password is valid: " + password); } else { System.out.println("Password is invalid"); } } else { System.out.println("Password is invalid"); } } else { System.out.println("Password is invalid"); } } }