面试题9

金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出。

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
package com.maoge;

public class {
private static final char[] data = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};

private static final char[] units = {'元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾'};

public static void main(String args[]) {
int money = 1123456987;

System.out.println(transform(money));
}

public static StringBuffer transform(int money) {
StringBuffer sb = new StringBuffer();
int i = 0;
while (money != 0) {
sb.insert(0, units[i++]);
int j = money % 10;
sb.insert(0, data[j]);
money = money / 10;
}
return sb;
}
}

limaodeng

scribble