如何对形如"1234556666"的String类型进行加减操作?我想过用Integer.parseInt()方法,但对于超过int所能存储的位数,就不行了.
如何"123456666".
请高手指点

解决方案 »

  1.   

    String oldStr="1234556666";
    int newIntNum=Integer.parseInt(old); //可以这样吧?/
      

  2.   

    用int 会溢出的!! 还是用long 好!!!!!!!
      

  3.   

    import java.math.*;public class TestBigDecimal{
    public TestBigDecimal(){}
    public long add(long one, long other){
    return one + other;
    }
    public BigDecimal add(BigDecimal one, BigDecimal other){
    return one.add(other);
    }
    public long multiply(long one, long other){
    return one*other;
    }
    public BigDecimal multiply(BigDecimal one, BigDecimal other){
    return one.multiply(other);
    }
    public static void main(String[] args){
    TestBigDecimal test = new TestBigDecimal();
    long longOne = (long)(Math.random()*1E19);
    long longOther = (long)(Math.random()*1E19);
    BigDecimal one = BigDecimal.valueOf(longOne);
    BigDecimal other = BigDecimal.valueOf(longOther);
    System.out.println (longOne+" + "+longOther+" = "+test.add(longOne,longOther));
    System.out.println (one+" add "+other+" = "+test.add(one,other));
    System.out.println (longOne+" * "+longOther+" = "+test.multiply(longOne,longOther));
    System.out.println (one+" multiply "+other+" = "+test.multiply(one,other));
    }
    }