这是我尝试使用 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");
}
}
}
}
如何使该方法起作用?我尝试使用不同类型的方法,但它仍然不起作用
此代码应输出数字而不是字符,每个字符都应更改为数字。我使用手机键盘作为将字符转换为数字的基础。