[英]Java: Using the isDigit function
Hey all I am working on a program in Java that checks a password for a few things such as is it 8 characters, is one character Uppercase, is one lowercase, and is there a number in the password. 嘿,我在Java程序中工作,它会检查密码是否有某些问题,例如8个字符,一个字符大写,一个小写以及密码中是否包含数字。 So far I have wrote the methods for checking length, upper and lower case, with no problems.
到目前为止,我已经编写了检查长度,大小写的方法,没有问题。 I cannot for the life of my understand why it isn't working with the isDigit().
我一生都无法理解为什么isDigit()无法正常工作。
No matter what input I throw in the method, it always returns true. 无论我在该方法中投入什么输入,它都始终返回true。 Anyone see my error?
有人看到我的错误吗?
Thanks in advance! 提前致谢!
public void setOneDigit(){
int i;
char ch;
boolean hasNumber = false;
for ( i = 0; i < password.length(); i++ ) {
ch = password.charAt(i);
if (Character.isDigit(ch));
{
hasNumber = true;
}
}
if(hasNumber == true)
{
hasOneDigit = true;
}
else
{
hasOneDigit = false;
}
}
Classic mistake: 经典错误:
if (Character.isDigit(ch));
{
hasNumber = true;
}
has to be 必须
if (Character.isDigit(ch))
{
hasNumber = true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.