ユーザーからフレーズを取得し、ユーザーが入力したフレーズの暗号化されたコードをユーザーに返すプログラムを作成する必要があります。データを保持するために、配列または列挙リストを使用する必要がありました。私は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]);
}
}
}
}
}