|  | 
 
| 
1 package com.duduli.li.util; 2
 3 import java.util.HashMap;
 4 import java.util.Map;
 5
 6 public class Convered {
 7
 8     public void check(){
 9
 10     }
 11
 12     public static int[] stringToInt(String s){
 13         if(s.length() == 0){
 14             System.out.println("please input the number");
 15             System.exit(0);
 16         }
 17         int [] values = new int[s.length()];
 18         for(int i=0; i<s.length(); i++){
 19             if(!Character.isDigit(s.charAt(i))){
 20                 System.out.println("you input has none digt");
 21                 System.exit(0);
 22             }
 23             values = Character.getNumericValue(s.charAt(i));
 24 //            System.out.print(values);
 25         }
 26         return values;
 27     }
 28
 29     public void conver(String s){
 30         Map<Integer, String> unitMap = new HashMap<Integer, String>();
 31         unitMap.put(0, "");
 32         unitMap.put(1, "十");
 33         unitMap.put(2, "百");
 34         unitMap.put(3, "千");
 35         unitMap.put(4, "万");
 36         unitMap.put(5, "十");
 37         unitMap.put(6, "百");
 38         unitMap.put(7, "千");
 39         unitMap.put(8, "亿");
 40         unitMap.put(9, "十");
 41         unitMap.put(10, "百");
 42         unitMap.put(11, "千");
 43
 44         Map<Integer, String> valueMap = new HashMap<Integer, String>();
 45         valueMap.put(1, "一");
 46         valueMap.put(2, "二");
 47         valueMap.put(3, "三");
 48         valueMap.put(4, "四");
 49         valueMap.put(5, "五");
 50         valueMap.put(6, "六");
 51         valueMap.put(7, "七");
 52         valueMap.put(8, "八");
 53         valueMap.put(9, "九");
 54         valueMap.put(0, "零");
 55
 56         int [] money = stringToInt(s);
 57         String sb = "";
 58         int leg = money.length;
 59         for(int i=0; i<leg; i++){
 60                 sb += valueMap.get(money)+unitMap.get(leg-i-1);
 61         }
 62         System.out.println(sb);
 63     }
 64
 65     /**
 66      * @param args
 67      */
 68     public static void main(String[] args) {
 69         // TODO Auto-generated method stub
 70         Convered c = new Convered();
 71         c.conver("5454545");
 72     }
 73
 74 }
 75
 | 
 |