大数BigInteger总结

BigInteger  大数:当然可以用来解决数据的溢出问题;

基本函数:

 1.valueOf(parament); 将参数转换为制定的类型

  比如 int a=3;

       BigInteger b=BigInteger.valueOf(a);

       b=3;

       String s=”12345”;

       BigInteger c=BigInteger.valueOf(s);

       c=12345

 

 2.add(); 大整数相加

   BigInteger a=new BigInteger(“23”);

   BigInteger b=new BigInteger(“34”);

   a.add(b);

 3.subtract(); 相减

 4.multiply(); 相乘

 5.divide();    相除取整

 6.remainder();取余

 7.pow();   a.pow(b)=a^b

 8.gcd();   最大公约数

 9.abs(); 绝对值

 10.negate();取反数

 11.mod(); a.mod(b)=a%b=a.remainder(b);

 12.max(); min();

 13.punlic int comareTo();

 14.boolean equals(); 是否相等

 15.BigInteger构造函数

  一般用到以下两种:

   BigInteger(String val);

   将指定字符串转换为十进制表示形式;

   BigInteger(String val,int radix);

   将指定基数BigInteger的字符串表示形式转换为BigInteger

.基本常量:

   A=BigInteger.ONE    1

   B=BigInteger.TEN    10

   C=BigInteger.ZERO   0

.基本操作

 1.读入:

 Scanner类定义对象进行控制台读入,Scanner类在Java.util.*包中

 Scanner cin=new Scanner(System.in);// 读入

 while(cin.hasNext())   //等同于!=EOF

 {

   int n;

   BigInteger m;

   n=cin.nextInt(); //读入一个int;

   m=cin.BigInteger();//读入一个BigInteger;

   System.out.print(m.toString());

 }

BigInteger(byte[])

把一个包含着(正负号)整数的二进制补码字节数组翻译为 BigInteger 

BigInteger(int, byte[])

把一个整数的 sign-magnitude 表示法翻译为 BigInteger 

BigInteger(int, int, Random)

返回有指定 bitLength(可能是素数)的随机选择的 BigInter 

BigInteger(int, Random)

返回一个随机数,均匀分布 [0, 2**numBits - 1] 之间
(
假设由 rndSrc 提供一个公平的随机源

BigInteger(String)

把一个字符串翻译为一个 BigInteger ,该字符串包含可选的负号,后面跟着一个或多个十进制数字序列。

BigInteger(String, int)

把一个字符串翻译为一个 BigInteger ,该字符串包含可选的负号,后面跟着一个或多个指定进制的数字序列。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值