The code I have so far:
public static boolean validPass(String sPass)
{
boolean y=false;
if(sPass.length()>10)
{
int i,j=0,k=0;
char c;
for(i=0;i<sPass.length();i++)
{
c=sPass.charAt(i);
if(c>='A' && c<='Z')
{
j++;
}
else if(c>='a' && c<='z');
else if (!(sPass.contains("&") ||
sPass.contains("-")
|| sPass.contains("%") || sPass.contains("_")
||sPass.contains("^")||sPass.contains("@")));
else if(c>='0' && c<='9')
{
k++;
}
else
{
break;
}
}
if(i==sPass.length())
{
if(k>2 && j>1)
{
y=true;
}
}
}
return y;
}
}
The test I'm failing:
String sValid1 = "Bryce^RON&123";
assertTrue(Q4.validPass(sValid1));
class Main
{
static boolean validPass(String sPass)
{
if(sPass.length()>10)
{
int i,j=0,k=0,l=0;
char c;
for(i=0;i<sPass.length();i++)
{
c=sPass.charAt(i);
if(c>='A' && c<='Z')
j++;
else if(c>='0' && c<='9')
k++;
else if(c>='a' && c<='z');
else if (c=='&' || c=='-' || c=='%' || c=='_' || c=='^' || c=='@')
l++;
else
return false;
}
if(k>2 && j>1 && l>0)
return true;
}
return false;
}
public static void main(String[] args)
{
String sValid1 = "Bryce^RON&123";
System.out.println(validPass(sValid1));
}
}
Get Answers For Free
Most questions answered within 1 hours.