我的两个密码验证方法有问题。 hasDigitsAndLetters方法应该检查字符串的所有字符是否都是数字和字母,第二种方法有两个数字应该检查通过中是否至少有两位数字,但问题在于对于预期的结果是true拖延假。如果有人可以帮忙。这里是代码。检查数字和字母的密码
//check if the whole string consists of digits and letters
public static boolean hasDigitsAndLetters(String pass)
{
for(int i=0; i<pass.length(); i++)
{
if(!Character.isLetterOrDigit((i)))
{
return false;
}
}
return true;
}
// check whether the password has at least 2 digits
public static boolean hasTwoDigits(String pass)
{
int counter = 0;
for(int i=0; i<pass.length(); i++)
{
if(Character.isDigit(i))
{
counter ++;
}
}
System.out.println("Number of digits: " + counter);
if(counter >= 2)
{
return true;
}
return false;
}
'Character.isxxx(pass.charAt(I))' – assylias 2012-07-31 18:38:57