I am writing a program to accept user name and password using following conditions- username must be min 8 characters. Password must have min 10 characters, 1 lowerCase, 1 upperCase, 1 digit should present in the password. I wrote a method setPassword() following all the conditions. When I try to execute I am getting StringIndexOutOfBound exception. I am unable to understand why I am getting that error:
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;
}
}
}
}
}
}
}
}