网上有很多版本,一看代码大长就感觉麻烦看不下去,最近辞职了要找工作又看见这道题就改了一下。
package com.test.money;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class Money { private static final String[] nums = new String[] { "一", "二", "三", "四", "五", "六", "七", "八", "九" };
private static final String[] units = new String[] { "十", "百", "千", "万", "亿" };
private static int count = -1;
private static final StringBuffer realMoney = new StringBuffer(); public static void main(String[] args) {
long tempNum = 843276157723L;
String temp = "八千四百三十二亿七千六百一十五万七千七百二十三";
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String money = reader.readLine();
reader.close();
System.out.println(showMeTheMoney(money));
} catch (IOException e) {
e.printStackTrace();
}
} public static String showMeTheMoney(String money) {
int length = money.length();
if (length < 1) {
return realMoney.toString();
}
int num = Integer.parseInt(money.substring(length - 1, length));
if (++count > 8) {
count = 0;
}
if (num != 0) {
realMoney.insert(0, nums[--num]);
if (length > 1) {
realMoney.insert(0, units[count > 3 ? count - 4 == 3 ? ++count - 4 : count - 4 : count]);
}
}
return showMeTheMoney(money.substring(0, money.length() - 1));
}
}

解决方案 »

  1.   

    LZ似乎对0没有作处理啊,遇到带0的就会出错了
      

  2.   

    每天回帖即可获得10分可用分!
      

  3.   

    试了3次,3次的结果:
    1.
    1024
    一百二十四
    2.
    007
    十七
    3.
    1001
    一十一
    ===========================
    路过,顺便拿走每日可用分10分~
      

  4.   

    唉 只考虑 结尾的〇了 开头和中间的〇都没有考虑