黑马程序员技术交流社区

标题: java code [打印本页]

作者: せR3n、何必装纯    时间: 2011-11-11 10:43
标题: java code
Java code



    import java.util.LinkedHashMap;
    import java.util.Map;

    public enum RomanNumeral {

    I(1), V(5), X(10), L(50), C(100), D(500), M(1000);
    private static Map<Integer, RomanNumeral> map = new LinkedHashMap<Integer, RomanNumeral>();
    public final int val;

    RomanNumeral(int val) {
    this.val = val;
    storeInMap();
    }

    private void storeInMap() {
    map.put(val, this);
    }

    public static RomanNumeral fromInt(int val) {
    return map.get(val);
    }

    public static void main(String[] args) {
    int sum = 0;
    for (int i = 0; i < 1000; i++) {
    if (fromInt(i) != null) {
    sum += i;
    }
    }
    System.out.println(sum);
    }
    }





问题:打印结果是什么?




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2