标签:rev uil ever style bre temp ati 相加 +=
static String bigNumberSum(String a,String b) { char[] charArrayA = new StringBuilder(a).reverse().toString().toCharArray(); char[] charArrayB = new StringBuilder(b).reverse().toString().toCharArray(); int length=charArrayA.length > charArrayB.length ? charArrayA.length : charArrayB.length; int[] result = new int[length +1]; int temp=0; for(int i=0;i<result.length;i++) { temp=result[i]; if(i < charArrayA.length) { temp+=charArrayA[i]-‘0‘; } if(i < charArrayB.length) { temp+=charArrayB[i]-‘0‘; } if(temp >= 10) { temp=temp-10; result[i+1]=1; } result[i]=temp; } StringBuilder sb=new StringBuilder(); for(int i=0;i<result.length;i++) { if(i==length) { if(result[i]==0) { break; } } sb.append(result[i]); } return sb.reverse().toString(); }
标签:rev uil ever style bre temp ati 相加 +=
原文地址:https://www.cnblogs.com/dongma/p/10045617.html