Java课程设计 大整数类 实现加法
来源:互联网 发布:破墙软件 编辑:程序博客网 时间:2024/06/02 19:28
大数类:
// Filename: BigInt.javaclass BigInt{BigInt(){}BigInt(int len){bigint = new int[len];}BigInt(String BI){for(int i = 0; i < BI.length(); i++){bigint[i] = BI.charAt(i) - '0';}}BigInt add(BigInt B){int carry = 0;int i;int maxlen = bigint.length > B.bigint.length ? bigint.length : B.bigint.length + 1;BigInt tmp = new BigInt(maxlen);for(i = 0; i < maxlen; i++){tmp.bigint[i] = 0;}for(i = maxlen; i >= 0; i--){tmp.bigint[i] = bigint[i] + B.bigint[i] + carry;carry = tmp.bigint[i] / 10;if(carry == 1){tmp.bigint[i] /= 10;}}return tmp;}void print(){int i = 0;if(bigint[0] == 0)i++;for( ; i < bigint.length; i++){System.out.print(bigint[i]);}}private int [] bigint;}
测试程序:
// Filename: BigIntTestDrive.javaimport java.io.*;import java.util.Scanner;public class BigIntTestDrive{public static void main(String[] args) {Scanner in = new Scanner(System.in);String strA, strB;System.out.println("Input the first integer:");strA = in.next();BigInt BigA = new BigInt(strA);System.out.println("Input the second integer:");strB = in.next();BigInt BigB = new BigInt(strB);BigInt BigC = BigA.add(BigB);BigC.print();}}
- Java课程设计 大整数类 实现加法
- php实现大整数加法
- html实现大整数加法
- php实现大整数加法
- 用链表实现大整数加法
- Java 实现大整数加法、乘法、阶乘运算
- 【LintCode-655】大整数加法(Java实现)
- 大整数加法(C程序实现)
- 用string实现大整数加法。
- 使用数组实现大整数加法
- C 大整数加法计算实现
- 用string实现大整数加法
- 用数组存储大整数,实现大整数的加法
- C++课程设计之大整数类
- C++课程设计之大整数类
- 总结:大整数类加法、乘法
- 大整数加法
- 大整数加法
- Android开发者指南(1) —— Android Debug Bridge(adb)
- Poj 2778 /1625 / 3691 AC自动机上的DP
- 数据库事务
- mysql备份还原
- IntelliJ idea 下如何使用spring2.5+log4j
- Java课程设计 大整数类 实现加法
- Linux全文查找、替换和删除
- js省市联动代码
- Memcache分组和同步机制的实现
- IOS 中 main()函数中UIApplicationMain后面的代码不执行...
- WPF程序设计指南第24张样式中DataTrigger中使用绑定的例子
- C# 新建文件夹、写文本文件
- 输出101~200内的质数
- vi编辑器不响应