题目内容:
你的程序要读入一个整数,范围是[-100000,100000]。然后,用汉语拼音将这个整数的每一位输出出来。
如输入1234,则输出:
yi er san si
注意,每个字的拼音之间有一个空格,但是最后的字后面没有空格。当遇到负数时,在输出的开头加上“fu”,如-2341输出为:
fu er san si yi
输入格式:
一个整数,范围是[-100000,100000]。
输出格式:
表示这个整数的每一位数字的汉语拼音,每一位数字的拼音之间以空格分隔,末尾没有空格。
输入样例:
-30
输出样例:
fu san ling
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int i;
String read = null;
int count = 1;
for ( i = Math.abs(n) ;i != 0; i=i/10)
{
if (i/10 != 0)
{
++count;
}
}
if ( n==0 )
{
System.out.print("ling");
}
else
{
while( n != 0)
{
if (n < 0)
{
System.out.print("fu ");
}
int digit = (int)Math.abs(n/Math.pow(10,count-1));
n = (int)Math.abs(n%Math.pow(10,count-1));
switch(digit)
{
case 0:
read ="ling";
break;
case 1:
read ="yi";
break;
case 2:
read ="er";
break;
case 3:
read ="san";
break;
case 4:
read ="si";
break;
case 5:
read ="wu";
break;
case 6:
read ="liu";
break;
case 7:
read ="qi";
break;
case 8:
read ="ba";
break;
case 9:
read ="jiu";
break;
}
if( count == 1)
{
System.out.print(read);
}
else
{
System.out.print(read+" ");
}
if (n == 0)
{
for ( int k = count-1;k != 0; --k )
{
if ( k != 1 )
{
System.out.print("ling ");
}
else
{
System.out.print("ling");
}
}
}
--count;
}
}
}
}