读入一个整数,用汉语拼音将这个整数的每一位输出出来
import java.util.Scanner;import javax.swing.plaf.synth.SynthStyleFactory;public class Main {private static Scanner in;public static void main(String[] args) {// TODO Auto-generated method stub//念整数/*你的程序要读入一个整数,范围是[-100000,100000]。然后,用汉语拼音将这个整数的每一位输出出来。如输入1234,则输出:yi er san si注意,每个字的拼音之间有一个空格,但是最后的字后面没有空格。当遇到负数时,在输出的开头加上“fu”,如-2341输出为:fu er san si yi输入格式:一个整数,范围是[-100000,100000]。输出格式:表示这个整数的每一位数字的汉语拼音,每一位数字的拼音之间以空格分隔,末尾没有空格。输入样例:-30输出样例:fu san ling********************************************************************************/in = new Scanner(System.in);int input = in.nextInt();int sign;int _input;int count = 0;//判断输入的数字是否在取值范围内while(input > 100000||input < -100000){System.out.println("Illegal input, please input again.");input = in.nextInt();}//如果为负数,先输出 fuif(input < 0){System.out.print("fu ");}_input = input;//计算数字的位数while(_input != 0){_input = _input/10;count ++;}//输出字符while(count > 0){int js = (int)Math.pow(10, count-1);//取数字的第一位sign = (int) (input /js);input = input % js;switch(Math.abs(sign)){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;default:break;}count --;}}
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
