//题目:将输入的阿拉伯数字转换的汉字的大写输出 |
02 |
03 | package test; |
04 |
05 | import java.io.*; |
06 |
07 | public class File_3 |
08 | { |
09 |
10 | /** |
11 | * @param args |
12 | * n 临时存储商 |
13 | */ |
14 | public void outNum( long number) |
15 | { |
16 | int i = 0 ; |
17 | int n = 0 ; |
18 | String str[] = { "十" , "百" , "千" , "万" , "十" , "百" , "千" , "亿" }; |
19 | String num[] = { "零" , "一" , "二" , "三" , "四" , "五" , "六" , "七" , "八" , "九" , "十" }; |
20 | int countLine = Long.toString(number).length(); |
21 | String count[] = new String[countLine]; |
22 | while (countLine >= 0 ) |
23 | { |
24 | n = ( int )(number / Math.pow( 10 ,countLine - 1 )); //获取该位的数字 |
25 | if (n != 0 ) //该位不为零时 |
26 | { |
27 | if (countLine == 1 ) //如果到个位数时,只输出大写数字 |
28 | { |
29 | count[i] = num[n]; |
30 | } |
31 | else //否则数字后面加职称 |
32 | { |
33 | count[i] = num[n] + str[countLine - 2 ]; |
34 | number = number % ( int )Math.pow( 10 ,countLine - 1 ); //取余 |
35 | } |
36 | i = i + 1 ; |
37 | countLine = countLine - 1 ; |
38 | System.out.print(num[n]); |
39 | System.out.print(str[countLine - 1 ]); |
40 | } |
41 | else //该位为零时 |
42 | { |
43 | System.out.print(num[n]); |
44 | i = i + 1 ; |
45 | countLine = countLine - 1 ; |
46 | } |
47 | } |
48 | } |
49 |
50 | public static void main(String[] args) throws IOException |
51 | { |
52 | // TODO 自动生成方法存根 |
53 | try |
54 | { |
55 | BufferedReader bin = new BufferedReader( new InputStreamReader(System.in)); |
56 | System.out.print( "请输入数字: " ); |
57 | long number = Long.parseLong(bin.readLine()); |
58 | File_3 f1 = new File_3(); |
59 | System.out.print( "转换大写为: " ); |
60 | f1.outNum(number); |
61 | } |
62 | catch (ArrayIndexOutOfBoundsException e) |
63 | { |
64 | |
65 | } |
66 | } |
67 |
68 | } |
69 |
70 | 运行结果: 请输入数字: 123456789 |
71 | 转换大写为: 一亿二千三百四十五万六千七百八十九 |
72 |
73 | |
74 |
75 | 请输入数字: 120365124 |
76 | 转换大写为: 一亿二千零三十六万五千一百二十四 |