ユーザーがメッセージを入力すると、プログラムがそれを数値に変換するプログラムを作成しようとしています (たとえば、a=1、b=2 など)。ただし、出力が得られません。どんな助けでも大歓迎です。私のコードは以下です。
import java.io.PrintStream;
import java.util.*;
public class AllRand25 {
public static void main(String[] args) {
int[] letterArray;
int[] wordArray;
int l = 0;
String messageWord;
char messageChar;
letterArray = new int[26];
int[] messageArray = new int[10];
int y = 0;
System.out.print("Enter your message");
Scanner scanner = new Scanner(System.in);
String message = scanner.nextLine();
while (scanner.hasNext()) {
messageWord = scanner.next(message);
l = messageWord.length();
Scanner charScan = new Scanner(messageWord);
for(int i = 0; i < messageWord.length(); i++){
messageChar = messageWord.charAt(i);
if (messageChar == 'a' || messageChar == 'A' || messageChar == 'A') {
messageArray[y] = 1;
} else if (messageChar == 'b' || messageChar == 'B') {
messageArray[y] = 2;
} else if (messageChar == 'c' || messageChar == 'C') {
messageArray[y] = 3;
} else if (messageChar == 'd' || messageChar == 'D') {
messageArray[y] = 4;
} else if (messageChar == 'e' || messageChar == 'E') {
messageArray[y] = 5;
} else if (messageChar == 'f' || messageChar == 'F') {
messageArray[y] = 6;
} else if (messageChar == 'g' || messageChar == 'G') {
messageArray[y] = 7;
} else if (messageChar == 'h' || messageChar == 'H') {
messageArray[y] = 8;
} else if (messageChar == 'i' || messageChar == 'I') {
messageArray[y] = 9;
} else if (messageChar == 'j' || messageChar == 'J') {
messageArray[y] = 10;
} else if (messageChar == 'k' || messageChar == 'K') {
messageArray[y] = 11;
} else if (messageChar == 'l' || messageChar == 'L') {
messageArray[y] = 12;
} else if (messageChar == 'm' || messageChar == 'M') {
messageArray[y] = 13;
} else if (messageChar == 'n' || messageChar == 'N') {
messageArray[y] = 14;
} else if (messageChar == 'o' || messageChar == 'O') {
messageArray[y] = 15;
} else if (messageChar == 'p' || messageChar == 'P') {
messageArray[y] = 16;
} else if (messageChar == 'q' || messageChar == 'Q') {
messageArray[y] = 17;
} else if (messageChar == 'r' || messageChar == 'R') {
messageArray[y] = 18;
} else if (messageChar == 's' || messageChar == 'S') {
messageArray[y] = 19;
} else if (messageChar == 't' || messageChar == 'T') {
messageArray[y] = 20;
} else if (messageChar == 'u' || messageChar == 'U') {
messageArray[y] = 21;
} else if (messageChar == 'v' || messageChar == 'V') {
messageArray[y] = 22;
} else if (messageChar == 'w' || messageChar == 'W') {
messageArray[y] = 23;
} else if (messageChar == 'x' || messageChar == 'X') {
messageArray[y] = 24;
} else if (messageChar == 'y' || messageChar == 'Y') {
messageArray[y] = 25;
} else if (messageChar == 'z' || messageChar == 'Z') {
messageArray[y] = 26;
}
else if (messageChar == ' ') {
messageArray[y] = 27;
}
y++;
}
}
for(int i = 0; i < messageArray.length; i++){
System.out.println(messageArray[i]);
}
}
}