classSolution{ public String multiply(String num1, String num2){ if("0".equals(num1) || "0".equals(num2)){ return"0"; } int length = num1.length() + num2.length(); int[] num = newint[length]; for (int i = num1.length() - 1; i >= 0; i--) { int a = num1.charAt(i) - '0'; for (int j = num2.length() - 1; j >= 0; j--) { int b = num2.charAt(j) - '0'; int c = a * b; // 十位 int d = c / 10; // 个位 int e = c % 10; int f = num[i + j + 1] + e; num[i + j + 1] = f % 10; num[i + j] = num[i + j] + d + f / 10; } } StringBuilder sb = new StringBuilder(); boolean flag = false; for (int i = 0; i < length; i++) { if (flag || num[i] > 0) { flag = true; sb.append(num[i]); } } return sb.toString().equals("") ? "0" : sb.toString(); } }