Java

博客介绍了Java中大数BigInteger的相关内容,包括导入语句、多种方法如读入、进制转换、类型转换、比较大小等,还提及了大数常量。此外,给出了类和二维数组相关参考博客链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、大数BigInteger

导入:import java.math.*;

方法:

  • nextBigInteger()    读入,例如Scanner scan = new Scanner(System.in); BigInteger n = scan.nextBigInteger();
  • BigInteger a = new BigInteger(str,radix)    进制转换,把radix进制的字符串str转化为BigInteger
  • toByteArray(),toString(),toString(radix进制),intValue(),longValue(),floatValue(),doubleValue()    类型转换

  • compareTo()    比较大小,返回int型,1大于,0等于,-1小于
  • max(),min()    返回较大/小的BigInteger型,用法a.max(b)
  • BigInteger.ZERO,BigInteger.ONE,BigInteger.TEN    大数常量0,1,10
add()subtract()multiply()divide()mod() / remainder()abs()negate()pow()gcd()
取余绝对值相反数幂运算最大公约数
and()or()xor()not()shiftLeft()shiftRight()setBit()testBit() 
&和|或^异或~取反<<左移>>右移将第n位二进制设为1测试第n位是否为1,返回Boolean型 

Tip:无特殊说明的都返回BigInteger型。不要忘记都需要赋值!例如:(相应的返回类型) 变量名=大数.方法(XXX);

二、类和二维数组

class Mat{
    BigInteger[][] m=new BigInteger[2][2];
}

 

参考博客:https://blog.youkuaiyun.com/weixin_44259720/article/details/87002816

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值