J Creator LEで作ってみたコードです。私はまだこれで初心者です、私はあなたが私を助けてくれることを願っています.
public class TelNumHelper{
public static void main(String[] Args){
String input = "1-800-FLO-WERS";
String output = " ";
int Key2,Key3,Key4,Key5,Key6,Key7,Key8,Key9,Key0;
Key2 = 2;
Key3 = 3;
Key4 = 4;
Key5 = 5;
Key6 = 6;
Key7 = 7;
Key8 = 8;
Key9 = 9;
Key0 = 0;
for(int i = 0;i<input.length();i++){
if(input.charAt(i)=='-'){
output = output + input.charAt(i);
}else{
output = output + valid(input.charAt(i));
}
}
public static char valid(char input){
if(input == A||input == B||input == C||input == 2){
System.out.println(Key2);
}else if(input == D||input == E||input == F||input == 3){
System.out.println(Key3);
}else if(input == G||input == H||input == I||input == 4){
System.out.println(Key4);
}else if(input == J||input == K||input == L||input == 5){
System.out.println(Key5);
}else if(input == M||input == N||input == O||input == 6){
System.out.println(Key6);
}else if(input == P||input == Q||input == R||input == S||input == 7){
System.out.println(Key7);
}else if(input == T||input == U||input == V||input == 8){
System.out.println(Key8);
}else if(input == W||input == X||input == Y||input == Z||input == 9){
System.out.println(Key9);
}else if(input == 0){
System.out.println(Key0);
}else{
System.out.println("Error");
}
}
}
}
メソッドを機能させるにはどうすればよいですか?いろいろな方法を試してみましたが、それでもうまくいきません
このコードは、文字ではなく数字を出力し、すべての文字を数字に変更する必要があります。文字を数字に変換するための基礎として、携帯電話のキーパッドを使用しました。