本帖最后由 qiuyedao 于 2010-10-17 06:33:15 编辑

解决方案 »

  1.   

    用字串作的方法都差不多,以下只是寫得精簡一點而已。public static String add(String s1, String s2) {
            byte[] a = s1.getBytes();
            byte[] b = s2.getBytes();
            byte[] c = new byte[a.length > b.length ? a.length + 1 : b.length + 1];
            int next = 0;
            for (int i = 0; i < c.length; i++) {
                c[c.length - i - 1] = 48;
                int ia = i >= a.length ? 48 : a[a.length - i - 1];
                int ib = i >= b.length ? 48 : b[b.length - i - 1];
                c[c.length - i - 1] = (byte) (next + ia + ib - 48);
                if (c[c.length - i - 1] - 48 >= 10) {
                    next = 1;
                    c[c.length - i - 1] -= 10;
                } else {
                    next = 0;
                }
            }
            String returnStr = new String(c);
            return returnStr.charAt(0) == '0' ? returnStr.substring(1) : returnStr.substring(0);
        }    public static void main(String[] args) {
            System.out.println(add("12345678909876543211234567890", "99999999999999999999999999999"));
        }
      

  2.   

    有个BigInteger的类,可以直接用那个类的
      

  3.   

    知道有BigInteger类,但是人家不让用,只能自己编写了一个能用的。