自己在建立一个Big number 类功能,高手帮忙来看看啊~

来源:百度知道 编辑:UC知道 时间:2024/05/30 09:20:51
运算大正整数的加法,乘法实现了,就是除法和余数还没成功,我把我乘法和加法的原码放上来,望高手能帮我解决除法和余数的实现啊~不胜感激啊!
private static String multiply(String s1, String s2) {
int s1Digit;
int s2Digit;
int productDigit;

String stepProduct;
String product;
String zeroes;
int carry;

// The final product before the multiplication starts is 0
product = "0";
// There are no '0's to be appended at the end of the first step
zeroes = "";
// Process all digits of the second number from least significant to
// most significant
for (int s2Index = s2.length() - 1; s2Index >= 0; s2Index--) {
s2Digit = s2.charAt(s2Index) - '0';
stepProduct = "";
carry = 0;
for (int s1Index = s1.length() - 1; s1Index >= 0; s1Index--) {
s1Digit = s1.charAt(s1Index) - '0';
productDigit = (s1Digit * s2Digit) + carry;
stepProduct = (productDig

我不清楚我这样回答你会不会满意。我也很想写代码给你做做样子,但似乎并没有这个必要。
java里面存在大整数这个类,而且它的各种方法都很完善,最重要的是,我们可以查看它的代码实现。你所需要的除法和余数的计算,都有包含在其中。
分别是divide和remainder方法。
在eclipse中可以很容易的查看它的代码,或者在sun的网站上也可以得到完整的源码包。
官方的源码,自然比我甚至很多高手的源码来得更高明一些。所以,我觉得还是不班门弄斧了。