A few days ago, my friend encountered a big number computing problem and I wrote it in a hurry.
To tell the truth, the Code is not very well written. It is a bit messy. Post it first, and then modify it in a few days.
Such as calculation: 9999999999999*1234567890123
- Package test;
- Public class bignumber {
- Public static double [] d1 = {9, 9, 9, 9, 9, 9, 9 };
- Public static double [] D2 = {1, 2, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
- Public static int [] calculate (double [] D1, double [] D2 ){
- Int result_length = 0;
- Int result_num = 0;
- Double [] d1_temp = NULL;
- Double [] d2_temp = NULL;
- Int [] result_over = NULL;
- If (d1.length = d2.length ){
- Result_length = d1.length;
- Result_num = result_length;
- D1_temp = D1;
- D2_temp = d2;
- } Else {
- Result_length = (d1.length> = d2.length )? D1.length: d2.length;
- Result_num = (d1.length <= d2.length )? D1.length: d2.length;
- D1_temp = (d1.length <= d2.length )? D1: D2;
- D2_temp = (d1.length> = d2.length )? D1: D2;
- }
- Double [] [] result = new double [result_num] [result_length + 1];
- Int temp = 0;
- For (INT I = result_num-1; I> = 0; I --){
- For (Int J = result_length-1; j> = 0; j --){
- Temp + = (INT) (d1_temp [I] * d2_temp [J]);
- Result [I] [J + 1] = TEMP % 10;
- Temp = temp/10;
- }
- Result [I] [0] = temp;
- Temp = 0;
- }
- Temp = 0;
- Int flag = 0;
- Result_over = new int [result_num + result_length];
- Int line_flag = result_over.length-1;
- For (int m = Result [0]. Length-1; m> = 0; m --){
- Flag = m;
- For (INT n = result. Length-1; n> = 0; n --){
- If (flag <= (result [N]. Length-1 )){
- Temp + = Result [N] [flag];
- } Else {
- Break;
- }
- Flag ++;
- }
- Result_over [line_flag --] = TEMP % 10;
- Temp = temp/10;
- If (M = 0 ){
- If (result. length> = 2 ){
- For (int A = result. Length-2; a> = 0; --){
- Flag = 0;
- Temp + = Result [a] [flag ++];
- For (int B = A-1; B> = 0; B --){
- If (flag <= (result [B]. Length-1 )){
- Temp + = Result [B] [flag];
- } Else {
- Break;
- }
- Flag ++;
- }
- Result_over [line_flag --] = TEMP % 10;
- Temp = temp/10;
- }
- }
- }
- }
- Return result_over;
- }
- Public static void main (string [] ARGs ){
- Int [] d_result = calculate (D1, D2 );
- For (INT I = 0; I <d_result.length; I ++) {// output result
- System. Out. Print ("" + d_result [I] + "");
- }
- }
- }
-----------------------
Result: 1 2 3 4 5 6 7 8 9 0 1 2 8 7 6 5 4 3 2 1 0 9 8 7 7