import java.util.Random;
public class PasswordRandomizer {
// Define the variables
private Random random = new Random();
private int passwordLength;
private String password = "";
public PasswordRandomizer(int length) {
// Initialize the variable
this.passwordLength = length;
}
public String createPassword() {
// write code that returns a randomized password
for(int i = 0; i < this.passwordLength; i++){
int j = random.nextInt();
char symbol = "abcdefghijklmnopqrstuvwxyz".charAt(j);
this.password = this.password + symbol;
}
return this.password;
}
}
我如何添加字符到一個字符串,我試過,但我得到這個錯誤:字符添加到字符串
"Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -414383904".
如果i = 5「abcde」,我不會打印出來,我發現一個錯誤,我沒有設置隨機數的限制,這給出了一些錯誤,但它仍然無法正常工作。 – UkoM 2014-10-30 17:30:29