请帮我看一下这两个方法怎么写?
1、
我传入一串数字做参数,返回这串数字的英文写法(纯英文)
例如,传12,返回twelve
传3000,返回three thousand
传50000,返回fifty thousand
传6000000,返回sisty million 
传1234567890,返回one billion two hundred and thirty four million five hundred and sisty seven thousand2、
我传入一串数字做参数,返回这串数字的英文写法(数字+英文)
传3000,返回3 thousand
传50000,返回50 thousand
传6000000,返回6 million 
传1234567890,返回1 billion 234 million 567 thousand谢谢!

解决方案 »

  1.   

    这东西貌似很繁琐啊,只写了一部分2位数的供LZ参考package com.ying;import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;public class Test_1 {
    private String method1(String p) {
    HashMap num = new HashMap();
    num.put("1", "one");
    num.put("2", "two");
    num.put("3", "three");
    num.put("4", "four");
    num.put("5", "five");
    num.put("6", "six");
    num.put("7", "seven");
    num.put("8", "eight");
    num.put("9", "nine");
    num.put("0", "zero");
    num.put("10", "ten");
    num.put("20", "twenty");
    num.put("30", "thirty");
    num.put("40", "fourty");
    num.put("50", "fifty");
    num.put("60", "sisty");
    num.put("70", "senenty");
    num.put("80", "eighty");
    num.put("90", "ninety");
    return (String) num.get(p);
    } // 个位
    public void method_0(String unit, ArrayList list) {
    if (!unit.equals("0")) {
    list.add(method1(unit));
    }
    } // 十位
    public void method_1(String decade, ArrayList list) {
    if (!decade.equals("0") && !decade.equals("1")) {
    list.add(method1(decade + "0"));
    }
    } private String method2(int in) throws ClassNotFoundException,
    SecurityException, NoSuchMethodException, InstantiationException,
    IllegalAccessException, IllegalArgumentException,
    InvocationTargetException {
    String str = "";
    if (in > 9 && in < 21) {
    str = String.valueOf(in) + "的映射还没定义";
    }
    char[] ch = String.valueOf(in).toCharArray();
    ArrayList<String> list = new ArrayList<String>();
    Class cls = Class.forName("com.ying.Test_1");
    Object obj = (Object) cls.newInstance();
    for (int i = ch.length - 1, j = 0; i > -1; i--, j++) {
    String method = "method_" + j;
    Method me = cls.getMethod(method, String.class, ArrayList.class);
    me.invoke(obj, String.valueOf(ch[i]), list);
    } Object[] temp = list.toArray();
    if (str.length() == 0) {
    for (int i = list.size() - 1; i > -1; i--) {
    str += (String) list.get(i) + " ";
    }
    }
    System.out.println(str);
    return str;
    } public static void main(String[] args) throws Exception {
    Test_1 x = new Test_1();
    for (int i = 0; i < 100; i++) {
    x.method2(i);
    }
    }
    }