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()); } }