java 大数类
来源:互联网 发布:手机短信删除恢复软件 编辑:程序博客网 时间:2024/06/05 15:47
import java.io.*;
class BigInt
{
int a[];
int len;
BigInt(String str)
{
{
len=str.length();
a=new int[len];
for(int i=0;i<len;i++)
{
this.a[i]=str.charAt(i)-48;
}
}
}
public BigInt bigplus(BigInt b)
{
BigInt sum;
int l;
int m=len-1;
int n=b.len-1;
int max;
if(len>=b.len)
{
l=b.len;
max=len-1;
sum=this;
}
else
{
l=len;
sum=b;
max=b.len-1;
}
for(int i=0;i<l;i++)
{
sum.a[max]=a[m]+b.a[n];
if(max!=0&&sum.a[max]>=10)
{
sum.a[max]=sum.a[max]-10;
sum.a[max-1]++;
}
m--;
n--;
max--;
}
return sum;
}
public void output()
{
for(int i=0;i<len;i++)
{
System.out.print(a[i]);
}
}
}
class TestBig
{
public static void main(String[] args) throws IOException
{
String str1;
String str2;
System.out.println("请输入大数1:");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str1=br.readLine();
System.out.println("请输入大数2:");
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
str2=br1.readLine();
BigInt a1=new BigInt(str1);
BigInt a2=new BigInt(str2);
BigInt a3=a1.bigplus(a2);
a3.output();
}
}
- Java大数类解决大数加法
- java 大数类
- JAVA大数类练手
- JAVA大数类练手
- java大数类
- Java 大数类
- JAVA大数类
- JAVA大数类练手
- Java大数类应用
- JAVA大数类练手
- Java 大数类
- java处理大数类
- Java大数类介绍
- JAVA大数类
- Java 大数类
- Java大数类
- java中的大数类
- Java大数类用法
- 用GDB调试程序
- 使用getJSON解决jquery跨域问题
- 腾讯面试题
- 需求分析的故事——如何练就需求分析的火眼金晴?
- VS2005下如何安装配置编译Qt4.5
- java 大数类
- 比較經典有味道的句子
- 使用内存映射文件读写大文件
- C/C++中sizeof的运用
- 软考终于结束了!!!
- iptables使用简介-01
- 五个SQL Server数据库备份与恢复必需知道并且会用的具体操作
- 1.2 使用iptables进行包过滤
- Linux的kill命令与信号控制