题目内容
你的程序要读入一个整数,范围是[-100000,100000]。然后,用汉语拼音将这个整数的每一位输出出来。
如输入1234,则输出:
yi er san si
注意,每个字的拼音之间有一个空格,但是最后的字后面没有空格。当遇到负数时,在输出的开头加上“fu”,如-2341输出为:
fu er san si yi
输入格式:
一个整数,范围是[-100000,100000]。
输出格式:
表示这个整数的每一位数字的汉语拼音,每一位数字的拼音之间以空格分隔,末尾没有空格。
输入样例:
-30
输出样例:
fu san ling
时间限制:1000ms内存限制:64000kb
代码
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in =new Scanner(System.in); int n = in.nextInt(); String sum = "", negative="", strkey = ""; if (n < 0) { n = -n; negative = "fu "; } else if (n==0) { sum = "ling"; } while ( n > 0 ) { switch (n % 10) { case 0: strkey = "ling"; break; case 1: strkey = "yi"; break; case 2: strkey = "er"; break; case 3: strkey = "san"; break; case 4: strkey = "si"; break; case 5: strkey = "wu"; break; case 6: strkey = "liu"; break; case 7: strkey = "qi"; break; case 8: strkey = "ba"; break; case 9: strkey = "jiu"; break; } if (sum.equals("")) { sum = strkey; } else { sum = strkey + " " + sum; } n /= 10; } System.out.println(negative + sum); in.close(); } }