public class testt10 { private static final char[] data = { '零', '壹', '贰', '叄', '肆', '伍', '陆', '柒', '捌', '玖' }; private static final char[] units = { '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟' }; @SuppressWarnings("resource") public static void main(String[] args) { while (true) { Scanner sc = new Scanner(System.in); long l = sc.nextLong(); System.out.println(convert(l)); } } public static String convert(long money) { StringBuffer sbf = new StringBuffer(); int uint = 0; while (money != 0) { sbf.insert(0, units[uint++]); sbf.insert(0, data[(int) (money % 10)]); money = money / 10; } // 去零 return sbf.toString().replaceAll("零[仟佰拾]", "零").replaceAll("零+万", "万") .replaceAll("零+亿", "亿").replaceAll("亿万", "亿零") .replaceAll("零+", "零").replaceAll("零圆", "圆"); } }
|