I am having trouble with figuring out why my code is incorrect and does not work the way I want it to. I am a high school student who started out in java not too long ago so my knowledge is very small so if you are helping please make it simple, I was ordered to write code that will receive as input a string that acts as a password and for the password to be accepted it needs to be at least 6 digits long and have at least 1 number and 1 letter.
Here's the code I wrote:
import java.util.*;
public class P21Q6
{
static Scanner reader = new Scanner(System.in);
public static void main(String[] args)
{
int i;
String warning = "Password needs to be 6 digits long and have at least 1 number and 1 letter";
boolean isProper = false;
System.out.println("Insert a password");
String pswrd = reader.next();
while (isProper = false)
{
System.out.println("Insert a password");
pswrd = reader.next();
if (pswrd.length() >= 6)
{
for (i = 0; i < pswrd.length(); i++)
{
if (((pswrd.charAt(i) <= 90 || pswrd.charAt(i) >= 65) || (pswrd.charAt(i) <= 122 || pswrd.charAt(i) >= 97)) && (pswrd.charAt(i) <= 57 || pswrd.charAt(i) >= 48))
{
isProper = true;
}
}
} else
{
System.out.println(warning);
}
}
System.out.println("Passord registered");
}
}
I know this looks very clunky but I really did try to fix the problem. Thank you so much!
Aucun commentaire:
Enregistrer un commentaire