public class Demo4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(method(sc.nextInt()));
}
public static String method(int num) {
String s = String.valueOf(num);
HashMap<Character, String> hs = new HashMap<>();
hs.put('0', "零");
hs.put('1', "一");
hs.put('2', "二");
hs.put('3', "三");
hs.put('4', "四");
hs.put('5', "五");
hs.put('6', "六");
hs.put('7', "七");
hs.put('8', "八");
hs.put('9', "九");
HashMap<Integer, String> h2 = new HashMap<>();
h2.put(1, "");
h2.put(2, "十");
h2.put(3, "百");
h2.put(4, "千");
h2.put(5, "万");
h2.put(6, "十万");
h2.put(7, "百万");
h2.put(8, "千万");
h2.put(9, "亿");
StringBuffer sb = new StringBuffer();
for (int i = s.length() - 1; i >= 0; i--) {
sb.append(h2.get(s.length() - i));
sb.append(hs.get(s.charAt(i)));
}
sb.reverse();
return sb.toString();
}
} |