用java程序实现两个整数相乘的过程
public class _两数相乘过程 {
public static void main(String[] args) {
//定义两个数组存储整数
int[] arr1 = {4,5,6,7};
int[] arr2 = {3,4,5,6};
int[] result = new int[arr1.length+arr2.length];
for (int i = arr2.length-1;i>=0;i--){
for (int j = arr1.length-1;j>=0;j--){
result [i+j] += arr2[i] * arr1[j];
}
}
//进位操作
for (int i =result.length-2;i>=0;i--){
int temp = result[i];
result[i] = temp%10;
result[i-1] +=temp/10 ;
if (i-1==0){
break;
}
}
//输出
for (int i = 0;i<=result.length-2;i++){
System.out.print(result[i]);
}
//验算
System.out.println();
System.out.println(4567*3456);
}
}
|