/**
* 關於兩個大的數值相乘
* 思路解決:
* 將str型別轉換成乙個物件訪問 包括 長度以及陣列訪問str的值
* 然後將兩個陣列相乘 存放在第三個數值中 然後將大於9的向前近衛
* 最後列印出這個相乘的
* 陣列 *
* @author meachalyang
* @since 2011-01-07 *
*/public class test catch (ioexception e)
/*** 定義兩個字串變數 獲取輸入的值
* 這段** 請不要嚴格 計較 哈哈 */
string strmula=strarry[0];
string strmulb=strarry[1];
/*** 將輸入的字串變數轉換到與字串本身等長的陣列中 */
//寫乙個儲存字串並轉換為陣列的方法
intintmula=strtoarray(strmula);
intintmulb=strtoarray(strmulb);
//然後將這個兩個陣列相乘 並儲存在第三個陣列中
/* 定義第三個陣列*/
/*** 列印 frist num and second num len logs *
*/system.out.println("frist num len:"+intmula.length);
system.out.println("second num len:"+intmulb.length);
//定義乙個mul陣列用於訪問結果
intintmulresult=new int[intmula.length+intmulb.length-1];
int num=0;
/*** 根據兩個轉型後的數值 進行乘法運算 */
getmulvalue(intmula, intmulb, intmulresult);
system.out.println("get mul len:"+intmulresult.length);
system.out.print("get mul :");
for (int i = 0; i < intmulresult.length; i++)
}/**
* 此方法封裝了 得到獲取乘集的演算法
* 根據 frist num &second num 逐步相乘的原理 例如
* 222*321 可以拆分為 2*100*3*100+2*100*2*10+200*1
* + 2*10*3*100+2*10*20+20*1
* + 2*300+2*20+20*1
* 正好對應陣列的每個索引位置
* * 然後將每個索引位置大於9的向前進一位 並保留餘數
* @param mulnuma 乘數1
* @param mulnumb 乘數2
* @param mulresult result */
private static void getmulvalue(int mulnuma, int mulnumb, int mulresult)
} //200*321 71262
//222*1+222*20+222*300
//666[2]+6660[1]+66600[0]
// 200*300+200*20+200*1 64200
// 10*300+10*20+10*1 6420
// 2*300+2*20+2*1 642
//剔除intstr3陣列中個位置上的大於9的數
for (int i = mulresult.length-1; i >0; i--) }
} /**
* 將字串每個字元的值 定義並儲存在陣列中
* @param str 傳入的字串
* @return */
@suppresswarnings("null")
public static int strtoarray(string str)
} return strtoarray; }
}
兩個大數相乘JAVA版
public class mymultiply public static void covertdata char data,int len public static void multiply char a,int alen,char b,int blen 對齊逐位相乘 for int j 0...
兩個大數相乘
兩個大數相乘 2007 08 27 00 35 question 1 用乙個整型陣列表示乙個大數,陣列的每個元素儲存大數的一位數字,則實際的大數d表示為 d a k 10的k 1次冪 a k 1 10的k 2次冪 a 2 10 a 1 其中a 0 儲存該大數的位數 實現兩個大數相乘 再此基礎上實現兩...
兩個大數相乘
兩個大數相乘 char multiply char char 給了兩個字串,每個都是代表了乙個很長的10進製表示的數 比如 char str1 23456789009877666555544444 char str2 346587436598437594375943875943875 最後求出他們的...