assignment

PHOTO EMBED

Thu Apr 22 2021 07:42:42 GMT+0000 (Coordinated Universal Time)

Saved by @ahmedqgqgq #java

import java.util.Scanner;

//Some websites impose certain rules for passwords,
//Write a java program that checks whether a string is valid passwords,
//suppose the password rule is as follows,
//A password must have at least eight characters,
//A password consists of only letters and digits, 
//A password must contain at least two digits,
//your program prompts the user to enter a password and displays"valid password",
//if the rule is followed or"invalid password otherwise",

public class Ok {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter the password:");
        String password=input.next();
        if(isLeastEightChara(password)&&isContainLeastTwoDigits(password)&&isOnlyLettersandDigits(password))
        {
            System.out.println("Valid password");
        }
        else
        {
            System.out.println("inValid password");

        }

        

    }
    public static boolean isLeastEightChara(String password)
    {
        if(password.length()<=8)
        {
            return true;
        }
        else
        {
            return false;
        }
    };
    public static boolean isContainLeastTwoDigits(String password)
    {
        int count=0;
        for(int i=0;i<password.length();i++)
        {
        char pass=password.charAt(i);
        if(Character.isDigit(pass))
        {
            count++;
        }
        }
        if(count>=2)
        {
            return true;
        }
        else
        {
            return false;
        }
    };
    public static boolean isOnlyLettersandDigits(String password){
        boolean a=false;
        for(int i=0;i<password.length();i++){
        char pass=password.charAt(i);
        if(Character.isDigit(pass)&&Character.isAlphabetic(pass)){
            a=true;
        }
        return a;
    }
    
}
    
}
content_copyCOPY