- /*
- 从键盘接受一个数字,列出该数字的中文表示格式
- 例如: 键盘输入123,打印出一二三
- 键盘输入3103,打印出三一零三
- */
- import java.util.*;
- class Answer2
- {
- public static void main(String[] args)
- {
- System.out.println("请输入数字:");
- Scanner sc=new Scanner(System.in);
- int k=sc.nextInt();
- Integer in=new Integer(k);
- String s=in.toString();
- char[] ch=s.toCharArray();
- StringBuilder sb=new StringBuilder();
- HashMap<Integer,String> hm=new HashMap<Integer,String>();
- hm.put(1,"一");
- hm.put(2,"二");
- hm.put(3,"三");
- hm.put(4,"四");
- hm.put(5,"五");
- hm.put(6,"六");
- hm.put(7,"七");
- hm.put(8,"八");
- hm.put(9,"九");
- hm.put(0,"零");
- Set<Integer> set=hm.keySet();
- Iterator<Integer> it=set.iterator();
- for (int i=0;i<ch.length ;i++ )
- {
- while (it.hasNext())
- {
- //System.out.println(ch[i]);
- //System.out.println(it.next());
- //(new Integer(ch[i]).equals(it.next()))
- int m=it.next();
- if (Integer.parseInt(String.valueOf(ch[i]))==m)
- {
-
- //System.out.println("请输入数字:1111111");
- sb.append(String.valueOf(hm.get(m)));
- continue;
- }
- }
- System.out.print(sb);
- }
-
- }
- }
复制代码 |
|