I think I'm getting close but after I compile if password is valid it says "Password is valid" message twice and I do not know why. Also I need to add in a loop and am not sure where or how. I am super new to this and am trying to understand my book at well as explainations on the web but I'm stuck.
I think I'm getting close but after I compile if password is valid it says "Password is valid" message twice and I do not know why.
Also I need to add in a loop and am not sure where or how. I am super new to this and am trying to understand my book at well as explainations on the web but I'm stuck.
Any guidence would be helpful. Here's my code so far:
import java.util.*;
public class Password
{
public static void main(String[] args)
{
int min =6;
int max=10;
int digit=2;
int upperCount=2;
int lowerCount=2;
String password;
Scanner scan = new Scanner(System.in);
System.out.println(" Enter a Password- must have at least 2 numbers, 2 uppercase & 2 lowercase letters.");
password = scan.nextLine();
if(password.length()>=min&&password.length()<=max)
{
for(int i =0;
i<password.length();i++)
{
char c = password.charAt(i);
if(Character.isUpperCase(c))
upperCount++;
else
if(Character.isLowerCase(c))
lowerCount++;
else
if(Character.isDigit(c))
System.out.println(" Your password is valid");
}
}
if(password.length()<min)
{
for(int i =0;i<password.length();i++)
{
char c = password.charAt(i);
if(Character.isLowerCase(c))
lowerCount++;
}
if(lowerCount>2)
{
System.out.println(" INVALID- Password must have at least 2 numbers, 2 uppercase & 2 lowercase letters.");
System.out.println(" Please try again.");
System.out.println(" Enter a Password- ");
}
}
{
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images