java吧 关注:1,230,804贴子:12,692,594
  • 11回复贴,共1

输入一串数字,然后输出中文字符,比如123输出一百二十三,求

只看楼主收藏回复

输入一串数字,然后输出中文字符,比如123输出一百二十三,求各位大佬帮帮忙,谢谢


IP属地:四川来自Android客户端1楼2018-04-13 10:46回复
    if判断取余


    IP属地:北京来自手机贴吧2楼2018-04-13 11:10
    回复
      可以说详细点吗,我还是不懂诶


      IP属地:四川来自Android客户端3楼2018-04-13 11:44
      回复
        public static void main(String[] args) {
        int i = 30567809;
        int l = String.valueOf(i).length();
        int j = 10;
        String s = "";
        String[] str = new String[] {"","十","百","千","万","十万","百万","千万","亿"};
        for (int k = 0; k < l; k++) {
        String chnum = "";
        int leftnum = i % j;
        switch (leftnum) {
        case 0:
        chnum = "零";
        break;
        case 1:
        chnum = "一";
        break;
        case 2:
        chnum = "二";
        break;
        case 3:
        chnum = "三";
        break;
        case 4:
        chnum = "四";
        break;
        case 5:
        chnum = "五";
        break;
        case 6:
        chnum = "六";
        break;
        case 7:
        chnum = "七";
        break;
        case 8:
        chnum = "八";
        break;
        case 9:
        chnum = "九";
        break;
        case 10:
        chnum = "十";
        break;
        default:
        break;
        }
        s = chnum.equals("零")?chnum+s:chnum+str[k]+s;
        i = (i-leftnum)/j;
        }
        System.out.println(s);
        }


        IP属地:浙江4楼2018-04-13 11:52
        收起回复
          晚上给你写一个吧,现在没空


          IP属地:福建来自Android客户端5楼2018-04-13 13:04
          收起回复
            static String[] units = {"","十","百","千","万","十万","百万","千万","亿","十亿","百亿","千亿","万亿" };
            static char[] numArray = {'零','一','二','三','四','五','六','七','八','九'};
            //将整数转换成汉字数字
            public static String formatInteger(int num) {
            char[] val = String.valueOf(num).toCharArray();
            int len = val.length;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
            String m = val[i] + "";
            int n = Integer.valueOf(m);
            boolean isZero = n == 0;
            String unit = units[(len - 1) - i];
            if (isZero) {
            if ('0' == val[i - 1]) {
            continue;
            } else {
            sb.append(numArray[n]);
            }
            } else {
            sb.append(numArray[n]);
            sb.append(unit);
            }
            }
            return sb.toString();
            }
            //将小数转换成汉字数字
            public static String formatDecimal(double decimal) {
            String decimals = String.valueOf(decimal);
            int decIndex = decimals.indexOf(".");
            int integ = Integer.valueOf(decimals.substring(0, decIndex));
            int dec = Integer.valueOf(decimals.substring(decIndex + 1));
            String result = formatInteger(integ) + "." + formatFractionalPart(dec);
            return result;
            }
            //格式化小数部分的数字
            public static String formatFractionalPart(int decimal) {
            char[] val = String.valueOf(decimal).toCharArray();
            int len = val.length;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < len; i++) {
            int n = Integer.valueOf(val[i] + "");
            sb.append(numArray[n]);
            }
            return sb.toString();
            }


            6楼2018-04-13 15:53
            回复
              谢谢啦


              IP属地:四川来自Android客户端7楼2018-04-13 16:27
              回复
                拿去当工具用吧



                IP属地:福建10楼2018-04-14 02:04
                回复
                  oo


                  IP属地:江西来自Android客户端11楼2018-04-14 06:13
                  回复