将输入的阿拉伯数字转换的汉字的大写输出

//题目:将输入的阿拉伯数字转换的汉字的大写输出
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                转换大写为: 一亿二千零三十六万五千一百二十四
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值