本帖最后由 fmi110 于 2015-9-12 21:32 编辑
a- import java.util.Scanner;
- public class Test {
- public static void main(String[] args) {
- long num = 101000001010l;
- String[] digit = {"零","壹","貳","叁","肆","伍","陆","柒","扒","玖"};
- String[] unit = {"整","圆","拾","百","仟","万","拾","百","仟","亿","拾","百","仟","万"};
- while(true){
- num = new Scanner(System.in).nextLong();
- char[] chArr = Long.toString(num).toCharArray();
- StringBuilder sb = new StringBuilder("");
- for(int i = 0;i < chArr.length;i++){
- String s = digit[Integer.parseInt(String.valueOf(chArr[i]))];
- String s2 = unit[chArr.length-i];
- sb.append(s).append(s2);
- }
- sb.append(unit[0]);
- String str = sb.toString();
- str = change(str);
- System.out.println(str);}
- }
- private static String change(String str) {
- String s = str.replaceAll("零[仟百拾]", "零");
- s = s.replaceAll("零+", "零").replaceAll("零亿", "亿").replaceAll("零万", "万");
- s = s.replaceAll("零圆", "圆").replace("亿万", "亿");
- return s;
- }
- }
复制代码
|
|