大数相加

大数相加类
package com.newer.strong;

public class BigNumber {
    
    private char[] demo;

    public void Math( String s1, String s2 ) {
        int sum = 0;                                                    //计算数位相加
        if( s1.length()0 ;i-- ) {
            int a1 = s1.charAt( i )-'0';
            int a2 = s2.charAt( i )-'0';
            if( flag == false ) {
                 sum = a1+a2;
            }else {
                sum = a1+a2+1;
                flag = false;
            }
            if( sum<10 ) {
                demo[i] =  (char) sum;
            }else {
                demo[i] = (char) (sum%10);
                flag = true;
            }
        }
        String s3 = new String( demo );
        System.out.println( s3 );
    }
}```

#####测试类
```java
package com.newer.strong;

public class TestBigNumber {
    
    public static void main( String[] args ) {
        BigNumber bigNumber = new BigNumber();
        
        String s1 = "1111111111111";
        String s2 = "2222222222222";
        
        bigNumber.Math(s1, s2);
        
    }
}```

你可能感兴趣的:(大数相加)