Java 编写一个程序,提示用户输入以字母表示的电话号码,并以数字输出相应的电话号码。我

Java 编写一个程序,提示用户输入以字母表示的电话号码,并以数字输出相应的电话号码。我,java,Java,我有以下任务: 编写一个程序,提示用户输入以字母表示的电话号码,并以数字输出相应的电话号码。如果用户输入的字母超过七个,则仅处理前七个字母。同时在第三位数字后输出–(连字符)。允许用户同时使用大小写字母以及单词之间的空格 下面是我尝试过的,但无法实现。请告知 package assignment; import java.util.*; public class Question3 { public static void main(String args[]) { Sc

我有以下任务:

编写一个程序,提示用户输入以字母表示的电话号码,并以数字输出相应的电话号码。如果用户输入的字母超过七个,则仅处理前七个字母。同时在第三位数字后输出–(连字符)。允许用户同时使用大小写字母以及单词之间的空格

下面是我尝试过的,但无法实现。请告知

package assignment;

import java.util.*;
public class Question3 {


    public static void main(String args[]) {

    Scanner keyboard = new Scanner(System.in);

    String telephone_letter;
    int index;



    System.out.println("Enter phone number :");
    telephone_letter = keyboard.nextLine();
    char aChar[] = telephone_letter.toCharArray();
    for(index=0;index<telephone_letter.length();index++){
    int[] number;
        number = new int[index];

        switch (aChar[index]) 
        {
            case 'A':
            case 'a':
            case 'B':
            case 'b':
            case 'C':
            case 'c':
                number[index] = 2;
                break;
            case 'D':
            case 'd':
            case 'E':
            case 'e':
            case 'F':
            case 'f':
                number[index] = 3;
                break;
            case 'G':
            case 'g':
            case 'H':
            case 'h':
            case 'I':
            case 'i':
                number[index] = 4;
                break;
            case 'J':
            case 'j':
            case 'K':
            case 'k':
            case 'L':
            case 'l':
                number[index] = 5;
                break;
            case 'M':
            case 'm':
            case 'N':
            case 'n':
            case 'O':
            case 'o':
                number[index] = 6;
                break;
            case 'P':
            case 'p':
            case 'Q':
            case 'q':
            case 'R':
            case 'r':
            case 'S':
            case 's':
                number[index] = 7;
                break;
            case 'T':
            case 't':
            case 'U':
            case 'u':
            case 'V':
            case 'v':
                number[index] = 8;
                break;
            case 'W':
            case 'w':
            case 'X':
            case 'x':
            case 'Y':
            case 'y':
            case 'Z':
            case 'z':
                number[index] = 9;
                break;
            default:
                System.out.println("Invalid Digit");
                break;


        }

    }

        System.out.println("achar" + number[0]+number[1]+number[2]+"-"+number[4]+number[5]+number[6]+number[7]);


    }
}
包分配;
导入java.util.*;
公开课问题3{
公共静态void main(字符串参数[]){
扫描仪键盘=新扫描仪(System.in);
字符串电话字母;
整数指数;
System.out.println(“输入电话号码:”);
电话字母=键盘.nextLine();
char aChar[]=电话信toCharArray();

对于(index=0;index我认为你的问题在于:

for(index=0;index<telephone_letter.length();index++){
    int[] number;

for(index=0;index这个程序不工作怎么办?“[I]无法让它工作”--你的程序是如何工作的?你会出错吗?你会给出什么样的输入?预期输出与实际输出的对比是什么?代码的哪一部分给了你问题?我们不会读一堆试图进入你头脑的代码。你应该提一个特定的问题。不要试图通过发布多条带有更多inf的注释来充实你的问题形式。编辑你的问题以添加更多信息。谢谢,伙计,你帮了我很多。向上投票和被接受的答案是正确的感谢;)我接受了答案,但在获得15个代表之前不能向上投票,只是想了解一下这个网站。