我必须制作一个程序,从用户那里获取一个短语,然后将他们输入的短语的加密代码返回给用户。我们将使用数组或枚举列表来保存数据。我使用 ROT13 进行编码(用字母表前后的 13 个位置替换每个英文字母)。我的程序运行,但它只允许我输入一个短语,然后说:
java.lang.ArrayIndexOutOfBoundsException: 26
at J4_1_EncryptionVer2.main(J4_1_EncryptionVer2.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
我不确定我的程序有什么问题!请帮忙!谢谢
import java.io.*;
public class J4_1_EncryptionVer2
{
public static void main (String [] args) throws IOException
{
BufferedReader myInput = new BufferedReader (new InputStreamReader (System.in));
String letterA [] = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String letterB [] = {"N","O","P","Q","R","S","T","U","V","W","X","Y","Z","A","B","C","D","E","F","G","H","I","J","K","L","M"};
System.out.println ("Please enter a phrase: ");
String message = myInput.readLine();
int x = 0;
while (x < message.length()){
String text = message;
String letter = Character.toString(text.charAt(x));
x++;
int i = 0;
if(letter.equals (letterA[i])){
System.out.println (letterB[i]);
}
while (!(letter.equals (letterA[i]))){
i++;
if(letter.equals (letterA[i])){
System.out.println (letterB[i]);
}
}
}
}
}