大数相加类
package com.newer.strong;
public class BigNumber {
private char[] demo;
public void Math( String s1, String s2 ) {
int sum = 0; //计算数位相加
if( s1.length()<s2.length() ) { //定义中间数组的长度
char[] demo = new char[ s2.length() ];
}else {
char[] demo = new char[ s1.length() ];
}
boolean flag = false; //设置数位相加大于10的判定
for( int i=demo.length-1; i>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);
}
}```