数字、小写转大写

 

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

 
public class NumConvertUpper {
    public static void main(String[] args) {
        List<String> num = Arrays.asList(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"});
        List<String> lower = Arrays.asList(new String[]{"零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "百", "千", "万", "亿"});
        List<String> upper = Arrays.asList(new String[]{"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖", "拾", "佰", "仟", "万", "亿"});

        while (true) {
            String line = new Scanner(System.in).nextLine();
            if ("\\q".equals(line)) {
                break;
            }
            int length = line.length();
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < length; i++) {
                int li = line.substring(i).length();
                String s0 = String.valueOf(line.charAt(0));
                String s = String.valueOf(line.charAt(i));
                boolean flag = num.contains(s0);
                if(flag == num.contains(s)){
                    if(flag){
                        int i1 = li / 4;
                        int i2 = li % 4;
                        System.out.println(i1);
                        System.out.println(i2);
                        String bs = upper.get(num.indexOf(s));
                        buffer.append(bs);
                        if(i2 == 0){
                            buffer.append(upper.get(12));
                        }else if(i2 == 3){
                            buffer.append(upper.get(11));
                        }else if(i2 == 2){
                            buffer.append(upper.get(10));
                        }else {
                            if(i != length -1) {
                                if (i1 == 4) {
                                    buffer.append(upper.get(13)).append(upper.get(14));
                                } else if (i1 == 3) {
                                    buffer.append(upper.get(13)).append(upper.get(14));
                                } else if (i1 == 2) {
                                    buffer.append(upper.get(14));
                                } else {
                                    buffer.append(upper.get(13));
                                }
                            }

                        }


                    }else {
                        buffer.append(upper.get(lower.indexOf(s)));

                    }
                }else {
                    throw new BusinessException("format is error!");
                }

            }
            System.out.println(buffer.toString());
        }

    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值