- Java code
private static final String[] digits = new String[]{" 零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};private static final String[] radices = new String[]{"", "拾", "佰", "仟"};private static final String[] bigRadices = new String[]{"", "万", "亿", "万"}; /** * 算法:输入数字,将其转换为中文。 * * @param num * 数字字符串 * @return 转换结果(中文) */ public static String covnt(String num) { String integral = num; // 整数部分 String outputCharacters = ""; // 最终转换输出结果 String d = null; int zeroCount = 0, p = 0, quotient = 0, modulus = 0; for (int i = 0; i < integral.length(); i++) { p = integral.length() - i - 1; d = integral.substring(i, i + 1); quotient = p / 4; modulus = p % 4; if (d.equals("0")) { zeroCount++; } else { if (zeroCount > 0) { outputCharacters += digits[0]; } zeroCount = 0; outputCharacters += digits[Integer.parseInt(d)] + radices[modulus]; } if (modulus == 0 && zeroCount < 4) { outputCharacters += bigRadices[quotient]; } } return outputCharacters; }
------解决方案--------------------
楼主能简单介绍下你想干什么吗 不要只是贴代码
------解决方案--------------------
想炫一下自己的代码吧~
------解决方案--------------------
这个转换的算法网上满天飞了
曾经也写过好几个,LZ可以搜以前的帖子