题目
一个纯数字的字符串能够转换成中文的数字描述;比如 12345 转换成 一万两千三百四十五
一种较为简单的实现方式:
public void change(String a) {
String[] str1 = new String[]{"","十", "百", "千", "万","十万"};
String[] str2 = new String[]{"","一","二","三","四","五","六","七","八","九","十"};
int count = 0;
StringBuffer no = new StringBuffer("");
int num = Integer.parseInt(a);
//判断是几位数
while(num > 0){
num /=10;
count++;
}
num = Integer.parseInt(a);
for(int i=0;i<a.length();i++) {
int b = Integer.parseInt(a.substring(i,i+1));
no.append(str2[b] + str1[count-i-1]);
}
System.out.println(no);