您的位置:首页 > 其它

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

2017-03-15 00:00 1171 查看
//题目:将输入的阿拉伯数字转换的汉字的大写输出

package test;

import java.io.*;

public class File_3
{

/**
* @param args
* n 临时存储商
*/
public void outNum(long number)
{
int i = 0;
int n = 0;
String str[] = {"十","百","千","万","十","百","千","亿"};
String num[] = {"零","一","二","三","四","五","六","七","八","九","十"};
int countLine = Long.toString(number).length();
String count[] = new String[countLine];
while(countLine >= 0)
{
n = (int)(number / Math.pow(10,countLine - 1));  //获取该位的数字
if(n != 0) //该位不为零时
{
if(countLine == 1) //如果到个位数时,只输出大写数字
{
count[i] = num
;
}
else //否则数字后面加职称
{
count[i] = num
+ str[countLine - 2];
number = number % (int)Math.pow(10,countLine - 1); //取余
}
i = i + 1;
countLine = countLine - 1;
System.out.print(num
);
System.out.print(str[countLine - 1]);
}
else //该位为零时
{
System.out.print(num
);
i = i + 1;
countLine = countLine - 1;
}
}
}

public static void main(String[] args)throws IOException
{
// TODO 自动生成方法存根
try
{
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
System.out.print("请输入数字: ");
long number = Long.parseLong(bin.readLine());
File_3 f1 = new File_3();
System.out.print("转换大写为: ");
f1.outNum(number);
}
catch(ArrayIndexOutOfBoundsException e)
{

}
}

}

运行结果: 请输入数字: 123456789
      转换大写为: 一亿二千三百四十五万六千七百八十九

        请输入数字: 120365124
转换大写为: 一亿二千零三十六万五千一百二十四
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐