1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| public static void main(String[] args) { Scanner sc = new Scanner(System.in); int money; while (true) { System.out.println("请输入金额:"); money = sc.nextInt(); if (money >= 0 && money <= 9999999) { break; } else { System.out.println("输入不合法,请重新输入!"); } } String moneyStr = ""; while (true) { int ge = money % 10; String number = getCapitalNumber(ge); moneyStr = number + moneyStr; money = money / 10; if (money == 0) { break; } } System.out.println(moneyStr); int count = 7 - moneyStr.length(); for (int i = 0; i < count; i++) { moneyStr = "零" + moneyStr; } System.out.println(moneyStr); String result = ""; String[] arr = {"佰", "拾", "万", "千", "佰", "拾", "元"}; for (int i = 0; i < moneyStr.length(); i++) { char ch = moneyStr.charAt(i); result = result + ch + arr[i]; } System.out.println(result); }
public static String getCapitalNumber(int number) { String[] arr = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; return arr[number]; }
|