import java.util.Scanner;
public class MoneyTrant
{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(true){
System.out.println("请输入你要转换的货币金额");
String money = in.next();
if(money.equalsIgnoreCase("over"))
break;
long moneyNumber = Long.parseLong(money);
trant(moneyNumber);
}
}
public static void trant(Long moneyNumber){
char[] chineseNumber = new char[]{'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};
char[] units = new char[]{'元','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟'};
int index = 0;
long lastNumber = 0;
StringBuilder sb = new StringBuilder();
while(moneyNumber !=0){
lastNumber = moneyNumber%10;
sb.insert(0,units[index++]);
sb.insert(0,chineseNumber[(int)lastNumber]);
moneyNumber = moneyNumber/10;
}
String money = sb.toString().replaceAll("零[拾佰仟]","零").replaceAll("零+亿","亿").replaceAll("零+万","零").
replaceAll("零+元","元");
System.out.println(money);
}
}
各位大神,代码可以复制运行就可以了,求指出其中的bug,有问题,我测试了,想的不多,还望多多指正
版主,帖子不要那么快分类好吗?我是想看看各位给的程序漏洞 |