我一直在研究一种生成密码的方法,该方法会将每个“S”更改为$。
请注意,我从另一个类中获取该短语,它始终大于 8 个字符
String key;
String store;
key = phrase.substring(0,1).toUpperCase();
phrase = key + phrase.substring(1,phrase.length());
System.out.println(phrase);
System.out.println(phrase.length());
for(int i = phrase.length(); i>0; i--) {
int sKey = phrase.indexOf('S');
store = "$" + phrase.substring(sKey+1,phrase.length());
phrase =phrase.substring(0,sKey)+store;
System.out.print(phrase);
}
}
但是之后我总是收到此错误
Exception in thread "main" Te$taaaajava.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(Unknown Source)
at edu.ilstu.Security.generatePassword(Security.java:15)
at edu.ilstu.SecurityApp.main(SecurityApp.java:57)
慕尼黑8549860
Helenr
繁星点点滴滴
相关分类