package offer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Problem04 { // 金额转换,阿拉伯数字的金额转换成中国传统的形式如: // (¥1011)->(一千零一拾一元整)输出。 private static final char[] data = new char[] { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; private static final char[] units = new char[] { '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿' }; public static void main(String[] args) { String str = ""; try { BufferedReader strin = new BufferedReader(new InputStreamReader(System.in)); System.out.print("请输入一个字符串:"); str = strin.readLine(); } catch (IOException e) { e.printStackTrace(); } StringBuilder result = new StringBuilder(); String string = str.substring(1); int num = Integer.valueOf(string); int count = 0; while (num != 0) { int temp = num % 10; result.append(units[count % 9]); result.append(data[temp]); count++; num = num / 10; } System.out.println(result.reverse()); } }