我正在编写一个程序来使用以下条件接受用户名和密码 - 用户名必须最少 8 个字符。密码必须至少包含 10 个字符,1 个小写字母,1 个大写字母,密码中应包含 1 个数字。我根据所有条件编写了一个方法 setPassword() 。当我尝试执行时,我收到 StringIndexOutOfBound 异常。我无法理解为什么会出现该错误:
public void setPassword(String password)
{
char ch;
if (password.length() <= 10) {
for (int i = 0; i <= password.length() - 1; i++) {
ch = password.charAt(i);
if (Character.isDigit(ch)) {
for (int j = 0; j <= password.length() - 1; j++) {
char ch1 = password.charAt(j);
if (Character.isUpperCase(ch1)) {
for(int k = 0; k <= password.length(); k++) {
char ch2 = password.charAt(k);
if (Character.isLowerCase(ch2)) {
this.password = password;
}
}
}
}
}
}
}
}