标签:array stat lse tostring ever += buffer end 无符号
public static String bigNumAdd(String s1,String s2){ if(s1==null||"".equals(s1)){ return s2; } if(s2==null||"".equals(s2)){ return s1; } char[] sArr1 = new StringBuffer(s1).reverse().toString().toCharArray(); char[] sArr2 = new StringBuffer(s2).reverse().toString().toCharArray(); int maxLen = sArr1.length>sArr2.length?sArr1.length:sArr2.length; int[] res = new int[maxLen+1]; for(int i=0;i<=maxLen;i++){ int i1 = i<sArr1.length?sArr1[i] - ‘0‘:0; int i2 = i<sArr2.length?sArr2[i] - ‘0‘:0; int tmp = i1+i2; if(tmp>=10){ res[i+1] += 1; res[i] += tmp -10; }else{ res[i] += tmp; } } StringBuffer sb = new StringBuffer(); if(res[res.length-1]!=0){ sb.append(res[res.length-1]); } for(int i=res.length-2;i>=0;i-- ){ sb.append(res[i]); } return sb.toString(); }
标签:array stat lse tostring ever += buffer end 无符号
原文地址:https://www.cnblogs.com/shijianchuzhenzhi/p/13173192.html