今天在本书看到用人民币中文来读取阿拉伯数字挺有意思的
这里写代码片public class NumRmb{ String[] hanArr = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; String[] unitStr = { "十", "百", "千", "万" }; public String toHanStr(String hanNum){ String result = ""; int length = hanNum.length(); for(int i=0;i<length;i++){ //char类型转int类型 int num = hanNum.charAt(i)-48; //如果不是最后一个数并且数不是零才加计量单位 if(i!=length-1 && num!=0){ result+=hanArr[num]+uniStr[length-2-i]; }else{ result+=hanArr[num]; } } return result; } public static void main(String[]args){ System.out.PRintln(new NumRmb.toHanstr("50806")); }}打印的结果是:伍万零捌百零陆
新闻热点
疑难解答