电话号码对应英语单词

package test;

/**

 * 编程之美  电话号码对应英语单词

 * @author Administrator

 *

 */

public class PhoneNumberTest {

//动态的n个for循环

    public static void main(String[]args)  

    {  

        int MaxLength = 9;  

        char c[][] = {

                {' '}, {' '},

                {'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'}

          };  

        int total[] = {0,0,3,3,3,3,3,4,3,4};  

        int number[] = {2,3,4}; //本例输入数字2,3,4  

        int answer[] = {0,0,0};  

        int len = 3;  

          

        while(true){  

            for(int i = 0; i < len; i++)  

                System.out.print(c[number[i]][answer[i]]+" ");

                System.out.println();

              

            int k = len - 1;  

            while(k >= 0){  

                if(answer[k] < total[number[k]] - 1){  

                    answer[k]++;  

                    break;  

                }  

                else{  

                    answer[k] = 0;  

                    k--;  

                }  

            }  

            if(k < 0)  

                break;  

        }  

    

    }}

 

你可能感兴趣的:(英语)