JAVA练习:金额转换

题目:键盘输入金额,将金额转换为大写,然后打印出账单上应写的文字。

1.实现思路:

2.程序运行截图:

3.程序实现代码:

public class jezh {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要转换的数字:");
        int xyz=sc.nextInt();
        if(xyz<=9999999){
        pj(xyz);
        }else{
            System.out.println("金额过大!");
        }
    }
    public static void pj(int a){
        String mmm="";
        while(a!=0){
            int temp=a%10;
            String nnn=zh(temp);
            mmm=nnn+mmm;
            a/=10;
        }
        int lll=7-mmm.length();
        for (int i = 0; i < lll; i++) {
            mmm="零"+mmm;
        }
        String[] dw={"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < 7; i++) {
            System.out.print(mmm.charAt(i)+dw[i]);
        }
    }
    public static String zh(int a){
        String[] abc={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return abc[a];
    }
}

将悲伤的事对半分吧,将快乐的事拼凑成双吧