题目描述
给出两个非负整数,求它们的乘积。
输入格式
输入共两行,每行一个非负整数。
输出格式
输出一个非负整数表示乘积。
输入输出样例
输入 #1复制
1
2
输出 #1复制
2
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
String b = scanner.next();
int[] num1 = new int[a.length() > b.length()?a.length():b.length() * 2];
int[] num2 = new int[a.length() > b.length()?a.length():b.length() * 2];
int[] result = new int[a.length() > b.length()?a.length():b.length() * 2];
for (int i = 0; i < result.length; i++) {
num1[i] = 0;
num2[i] = 0;
result[i] = 0;
if (i < a.length()) {
num1[i] = a.charAt(a.length()-1 - i) - '0';
}
if (i < b.length()) {
num2[i] = b.charAt(b.length()-1-i) -'0';
}
}
int sum = 0;
for (int i = 0; i < result.length ; i++) {
for (int j = 0; j < result.length;j++){
result[i] += ((num2[i] * num1[j]) * Math.pow(10,j)) * Math.pow(10,i) ;
}
}
for (int i = 0; i < result.length;i++){
sum += result[i];
}
System.out.println(sum);
}
}