//不考虑乘积过大的结果,默认乘积一定小于int的最大值
public class Test{
public static void main(String args[]) {
String num1="123";
String num2="12345";
//1.把num1和num2转化为对应的整数
char[] arr1=num1.toCharArray();
char[] arr2=num2.toCharArray();
int number1=numberZhuanhuan(arr1,num1);
System.out.println("第一个数字是:"+number1);
int number2=numberZhuanhuan(arr2,num2);
System.out.println("第二个数字是:"+number2);
int mult=number1*number2;
System.out.println("数字形式的结果:"+mult);
String result="";
result=mult+result;
System.out.println("字符串形式的结果:"+result);
}
public static int[] Zhuanhuan(char[]arr,String num1) {
int[]arr1=new int[arr.length];
arr=num1.toCharArray();
for(int i=0;i<arr1.length;i++) {
arr1[i]=(int)(arr[i]-48);
}
return arr1;
}
public static int numberZhuanhuan(char[] arr,String num1) {
int[] arr2=Zhuanhuan(arr,num1);
int number=0,n=1,i=1;
while(arr2.length-i>=0) {
number=number+arr2[arr2.length-i]*n;
n=n*10;
i++;
}
return number;
}
}