BigInteger大整数详解

import java.math.BigInteger;

public class BigIntegerTest {
public static void main(String[] args){

//1、BigInteger 类的基本常量
System.out.println(BigInteger.ZERO); // --0
System.out.println(BigInteger.ONE); // --1
System.out.println(BigInteger.TEN); // --10
testBigInteger();
}

//BigInteger 大整数类的用法
public static void testBigInteger(){
//基本的参数 将制定的数据类型转换未大整数类型
int a = 10;
String s = "123456";
BigInteger b = BigInteger.valueOf(a);
BigInteger s_n = BigInteger.valueOf(Long.valueOf(s));
System.out.println("b="+b+" s_n="+s_n);//b=10 s_n=123456

//大整数相加 构造值为 10 的大整数类型数据
BigInteger a_n = new BigInteger("10");
BigInteger b_n = new BigInteger("20");
BigInteger c_n = a_n.add(b_n);
System.out.println(c_n);

//大整数相减
BigInteger j_n1 = BigInteger.valueOf(25);
BigInteger j_n2 = BigInteger.valueOf(15);
//j_n1-j_n2 = ?
System.out.println("两个数相减:"+j_n1.subtract(j_n2)); // -=10
System.out.println("两个数相乘"+j_n1.multiply(j_n2)); // *=375
System.out.println("两个数相除取整数:"+j_n1.divide(j_n2));
System.out.println("j_n1的次方数:"+j_n1.pow(3));
System.out.println("取反数后为:"+j_n1.negate());
System.out.println("取模余数"+j_n1.mod(a_n)); // == %
System.out.println("比较两个数,取大值:"+j_n2.max(b_n));

/* 常用的函数 */
/*
negate();
min();

*/

//构造函数
//BigInteger(String val); 指定字符串转换为十进制的表示形式
//BigInteger(String val,int radix); 指定基数的BigInteger的字符串表示形式转换为BigInteger



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值