学习心得——金钱大小写转换

1.难点在于金额的每个数字的大小写转换还有单位的插入

2.字符串的遍历和字符数组的遍历调用方式不同,千万不要搞混了,字符串要是想定位某个字符的话需要使用  string.charAt(i)这个函数.字符数组的话就是跟普通数组一样调用即可

package test.test1;

import java.util.Scanner;

public class test10 {
    public static void main(String[] args) {
        System.out.println(unit(number()));
    }
    public static String capitalnumber(int number){
        String []  capital={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return capital[number];
    }
    public static String number(){
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入金额:");
        int money=sc.nextInt();
        int ge;
        int count=0;
        String result = "";
        if (money>=0&&money<=9999999) {
            while (true) {
                ge = money % 10;
                result = capitalnumber(ge) + result;
                money = money / 10;
                count = count + 1;
                if (money == 0) {
                    break;
                }
            }
            for (int i = 0; i < 7 - count; i++) {
                result = "零" + result;
            }
        }else {
            System.out.println("输入金额不合法,请检查后重试");
            System.exit(0);
        }
        return result;
    }
    public  static  String unit(String arr){

        String[] unitmoney={"佰","十","万","千","佰","十","元"};
        String result="";
        for (int i = 0; i < unitmoney.length; i++) {
            result=result+arr.charAt(i)+unitmoney[i];
        }
        return result;
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落日与鲸.520

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值