你的程序要读入一个整数,范围是[-100000,100000]。然后,用汉语拼音将这个整数的每一位输出出来。
如输入1234,则输出:
yi er san si
注意,每个字的拼音之间有一个空格,但是最后的字后面没有空格。当遇到负数时,在输出的开头加上“fu”,如-2341输出为:
fu er san si yi
我的做法:
package com.learn;
import java.util.Scanner;
public class ReadInteger {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number = in.nextInt();
if (number >= -100000 & number <= 100000) {
if (number < 0) {
System.out.print("fu ");
number = -number;
}
int j = 100000;
while (j >= 1) {
int m = number / j;
if (m != 0) {
int z = m % 10;
switch (z) {
case 0:
System.out.print("ling ");
break;
case 1:
System.out.print("yi ");
break;
case 2:
System.out.print("er ");
break;
case 3:
System.out.print("san ");
break;
case 4:
System.out.print("si ");
break;
case 5:
System.out.print("wu ");
break;
case 6:
System.out.print("liu ");
break;
case 7:
System.out.print("qi ");
break;
case 8:
System.out.print("ba ");
break;
case 9:
System.out.print("jiu ");
break;
}
}
j /= 10;
}
}
else
{
System.out.print("您输入的数不在范围内");
}
}
}