static String bigNumMul(String num1,String num2) {
char num1Chars[] = num1.toCharArray();
char num2Chars[] = num2.toCharArray();
int num1Ary[] = new int[num1Chars.length];
for (int i = 0; i < num1Ary.length; i++) {
num1Ary[i] = num1Chars[i] - '0';
}
int num2Ary[] = new int[num2Chars.length];
for (int i = 0; i < num2Ary.length; i++) {
num2Ary[i] = num2Chars[i] - '0';
}
int resAry[] = new int[num1Chars.length + num2Chars.length - 1];
for (int i = 0; i < num1Ary.length; i++) {
for (int j = 0; j < num2Ary.length; j++) {
resAry[i + j] += num1Ary[i] * num2Ary[j];
}
}
for (int i = resAry.length - 1; i > 0; i--) {
resAry[i - 1] += resAry[i] / 10;
resAry[i] = resAry[i] % 10;
}
int shouwei = resAry[0] / 10;
resAry[0] = resAry[0] % 10;
String res = shouwei == 0 ? "" : "1";
for (int i = 0; i < resAry.length; i++) {
res += resAry[i];
}
return res;
}
网友评论