我写了凯撒密码的代码,但它不工作...请帮我解决这个问题。我需要帮助理解java.lang.StringIndexOutOfBoundsException
import java.io.IOException;
import java.util.Scanner;
public class test1 {
public static void main(String[] args) throws IOException {
System.out.println("enter the String");
StringBuffer str = new StringBuffer(new Scanner(System.in).nextLine());
System.out.println("encrypting the String . . ." +str);
for(int j=0; j<str.length(); j++){
for(int i=0; i<256; i++) {
if((char)i == str.charAt(j)){
str.setCharAt(j, (char)(i+3));
}
}
}
System.out.println("encrypted String . . .");
}
}
这里您的解决方案的作品并没有更多的java.lang.StringIndexOutOfBoundsException 现在还有另一个问题发生。 。 。 。 我尝试了不同的输入,但它一直回复相同的答案:??????
'J开头<= str.length()'索引是基于0。 – 2015-02-11 06:32:48
你的建议解决了我的问题。 。 。但是现在当我运行程序时出现另一个错误,它显示答案?????我尝试了不同的输入,但每次只有一个输出:?????? – 2015-02-11 08:05:39