I keep getting an error that states my String index is out of range at String.charAt, PasswordGenerator.matchCharAt, and Driver.main. I don’t know what that means exactly. Also my characters won’t append to one line from the stringbuilder class that I already instantiated. I was wondering if maybe that was caused by the String index error or whether it was my fault.
public class Driver {
public static void main(String[] args) {
int length=0;
int MaxNumber=100;
StringBuilder password = new StringBuilder();
do {
if (PasswordGenerator.matchLength (length))
System.out.println("The length of the character is " + length);
length++; // length is randomly picked
} while (length < MaxNumber ); // or <100
int index = 0;
char f = 0;
for (int d = 0; d < 127 || ; d++) {
if (PasswordGenerator.matchCharAt(f, index))
d = (char) index;
char aChar = (char)d;
password.append(aChar);
System.out.println("Password is: " + aChar);
index++;
}
}
}
You are getting the error since
idxwill vary between 0 and 127. The password from thePasswordGeneratoris probably not that long. For example, before you ask whether there is a match at index 57, you must ask if 57 is less than the length of the password.So your task is to guess the password that the generator saves? Then you should do this: