1其实吧跟我们做的哪个基础差不多啊,就是把数字转化成大写数字,具体代码请参照
import java.io.*;
import java.lang.String;
public class change
{
public static void main(String agrs[])
{
//Money用于存放输入的金额数
long Money=0;
String Mon[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
String Mon1[]={"拾","佰","仟","万","拾万","百万","仟万","亿","拾亿","百亿","仟亿"},
je[]=new String[30];//je[]数组用于存放数字金额被转换后的数字
//n用于测试您是否有金额转换
int n=agrs.length;
if(n==0)
System.out.println("请输入需要转换的金额:");
//将输入的金额转化成long型的数据
else
{
Money=Long.parseLong(agrs[n-1]);
}
//bitt用于存放第几个需转换的金额数字,
int bitt=0,j,k=-1,i=0;
//转换过程
while(Money!=0)
{
bitt=(int)(Money%10L);
//计算出每个数字对应的大写值
for(j=0;j<Mon.length;j++)
{
if(j==bitt)break;
}
//将相应的值存入je[]中
if(k!=-1){je[i]=Mon1[k];i++;}
je[i]=Mon[j];i++;
Money=Money/10;
k++;
if(Money==0)
{
//输出转换后的金额
System.out.print("您输入的金额为:");
i--;
for(;i>=0;i--)
System.out.print(je[i]);
}
}
}
}
|