This content has been marked as final. Show 3 replies
the3rdhero wrote:squares: you have numbers in there that don't correspond to ASCII characters. You may want to limit the range of random numbers allowed.
I need to generate a password of random letters and numbers, I've been successful so far, but what I need to do is take the password I generated, delete one character, add a number to the end. Once that's done, I need to search the password for the letters L and O and replace them with underscore.
When I call makeBetterPassword() - It outputs : 4 random letters and a bunch of squares
When I call makeEvenBetterPassword() - I get the following error.So the original password doesn't have any "l" characters and returns -1. You have to allow for this.
Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
the3rdhero wrote:How what?
I'm still learning Java, aint got the best knowledge :(
To limit the range of random numbers use the method of Random that takes the upper limit as a paramater.
To handle indexOf returning a -1 then use an if statement that only does something if the value returned is not -1.