I also need the password to check for a digit. I am suppose to use: isDigit(), i
ID: 3627197 • Letter: I
Question
I also need the password to check for a digit. I am suppose to use: isDigit(), isUpperCase() and isLowerCase but don't know where to input them.
/***************************************************************
* Password
*
* This program determines if a password is valid or not.
**************************************************************/
import java.util.Scanner;
class Password
{
static boolean validpass(String p)
{
int count = 0;
for(int i=0; i
{
if((p.charAt(i)>=65 && p.charAt(i)<=90) ||(p.charAt(i)>=97 && p.charAt(i)<=122) || (p.charAt(i)>=48 && p.charAt(i)<=57) )
{
continue;
}
else
return false;
}
if(p.contains("and") || p.contains("end"))
return false;
return true;
}
public static void main(String[] a)
{
Scanner in = new Scanner(System.in);
System.out.println("Please Enter Password ");
String p = in.nextLine();
if(validpass(p))
System.out.println("Valid Password");
else
System.out.println("InValid Password");
}
}
Explanation / Answer
please rate - thanks
/***************************************************************
* Password
*
* This program determines if a password is valid or not.
**************************************************************/
import java.util.Scanner;
public class PassWord
{
public static boolean validpass(String p)
{
int count = 0;
for(int i=0; i<p.length();i++)
{
if(Character.isDigit(p.charAt(i)) || Character.isUpperCase(p.charAt(i))||Character.isLowerCase(p.charAt(i) ))
{
continue;
}
else
return false;
}
if(p.contains("and") || p.contains("end"))
return false;
return true;
}
public static void main(String[] a)
{
Scanner in = new Scanner(System.in);
System.out.println("Please Enter Password ");
String p = in.nextLine();
if(validpass(p))
System.out.println("Valid Password");
else
System.out.println("InValid Password");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.