java(字符串)练习

需求:键盘录入一个一万一下的数字,将数组变为大写汉字。

import java.util.Scanner;

public class Boke {
    public static void main(String[] args){
        Scanner Sc=new Scanner(System.in);
        int money = 0;
        while (true){
            System.out.print("请输入一个10000以内的数字:");
            money=Sc.nextInt();
            if(money>=0&&money<10000){
                break;
            }else
                System.out.println("输入错误请重新输入:");
        }
        String con = "";
        while(true){
            int ge = money%10;
            money=money/10;
            String ayue = Ayue(ge);
            con = ayue+con;
            if(money==0)
                break;
        }
        System.out.println(con);
    }

    public static String Ayue(int money){
        String[] arr = {"壹","贰","叁","肆","伍","陆","柒","捌","玖"};
        return arr[money-1];
    }
}

  

 

posted @ 2023-11-08 16:40  小菜阿跃  阅读(18)  评论(0)    收藏  举报