package com.chenqian.test;
import java.awt.image.BufferStrategy;
import java.util.Scanner;
public class NumberToUpper {
/** 大写数字 */
private static final char[] big = "零壹贰叁肆伍陸柒捌玖".toCharArray();
/** 整数部分的单位 */
private static final char[] iunit = "元拾佰仟万亿".toCharArray();
/** 小数部分的单位 */
// private static final char[] dunit = {'角','分'};
private static final String toChinese(String num) {
char[] arabia = num.toCharArray();
int length = num.length();
StringBuffer result = new StringBuffer(length * 2);
for (int i = 0; i = 9) {
if (varlen == 9)
c = iunit[5];
else
c = iunit[varlen - 9];
} else if (varlen >= 5) {
if (varlen == 5)
c = iunit[4];
else
c = iunit[varlen - 5];
} else
c = iunit[varlen - 1];
return c;
}
public static void main(String[] args) {
System.out.print("请输入需要转换的金额(13位整数):");
Scanner scanner = new Scanner(System.in);
String number = scanner.nextLine();
String result;
// String expression = "\\d{1,13
}";
String expression = "[1-9]\\d{0,12}";//正则表达式
if (number.matches(expression))
result = toChinese(number);
else
result = "输入有误,无法计算";
System.out.println(result);
System.out.print("是否继续(Y/N):");
String yn = scanner.next();
if(yn.equalsIgnoreCase("y"))
main(args);
else
System.exit(0);
}
}
数字转换金额
最新推荐文章于 2024-08-14 23:49:28 发布