package com.itheima.Demo;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
//需求:输入阿拉伯数字,输出对应的中文大写格式
//例如:11000,输出壹万壹仟
public class Teat12 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个整数:");
int b;
while (true) {
String line = sc.nextLine();
try {
b = Integer.parseInt(line);
break;
} catch (Exception e) {
try {
BigInteger big = new BigInteger(line);
System.out.println("你输入的整数过大,请重新输入:");
} catch (Exception e1) {
try {
BigDecimal bd = new BigDecimal(line);
System.out.println("你输入的是小数,请重新输入:");
} catch (Exception e2) {
System.out.println("你输入的是非法字符,请重新输入:");
}
}
}
}
jishu(b);
}
public static void jishu(int b) {
StringBuffer str = new StringBuffer();
char[] cs = (b + "").toCharArray();
String[] js = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String[] ws = { "元整", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾" };
for (int i = cs.length - 1; i >= 0; i--) {
int a = Integer.parseInt(cs[cs.length - 1 - i] + "");
str.append(js[a / 1] + ws[i]);
}
System.out.println(str);
}
}
有点小瑕疵....... |