Design and implement a Java program name it PasswordTest tha
Solution
PasswordTest.java
import java.util.Scanner;
public class PasswordTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter password: \");
String password = scan.next();
boolean status = false;
int lowerLetterCount = 0;
int upperLetterCount = 0;
int digitCount = 0;
int otherLetterCount = 0;
if(password.length() >= 8){
for(int i=0; i<password.length(); i++){
char ch = password.charAt(i);
if(ch >= \'a\' && ch <= \'z\'){
lowerLetterCount++;
}
else if(ch >= \'A\' && ch <= \'Z\'){
upperLetterCount++;
}
else if(ch >= \'1\' && ch <= \'9\'){
digitCount++;
}
else{
otherLetterCount++;
}
}
}
if(lowerLetterCount > 0 && upperLetterCount > 0 && digitCount > 0 && otherLetterCount > 0){
status = true;
}
String s = \"\";
if(status){
s = \"Valid\";
}else{
s = \"Invalid\";
}
System.out.println(\"Entered Password: \"+password );
System.out.println(\"Verdict: \"+s);
}
}
Output:
Enter password:
CS1301/99
Entered Password: CS1301/99
Verdict: Invalid

