BigInteger的一些基本用法

BigInteger

BigInteger 是java.math包中的一个类,今天通宵网吧无聊,就顺便看去看了以下,学习了以下基本用法,担心以后忘记可以回来看看。

基本方法:

import java.util.*;
import java.math.*;

public class main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		String big_a = in.nextLine();
		String big_b = in.nextLine();
		
		BigInteger test_a = new BigInteger(big_a);
		BigInteger test_b = new BigInteger(big_b);
		
		System.out.println("加法操作"+test_a.add(test_b));
		System.out.println("加法操作"+test_a.add(new BigInteger("100")));
		//BigInteger的操作都是针对BigInteger类操作的,所以如果是普通的int类型要转换成BigInteger类的,以下都是

		System.out.println("减法操作"+test_a.subtract(test_b));
		System.out.println("乘法操作"+test_a.multiply(test_b));
		System.out.println("除法操作"+test_a.divide(test_b));//取商
		System.out.println("取商操作"+test_a.divideAndRemainder(test_b)[0]);
		System.out.println("取余操作"+test_a.divideAndRemainder(test_b)[1]);
		System.out.println("做2次方操作"+test_a.pow(2));
		System.out.println("取相反数"+test_a.negate());
		//感觉divide()和divideAndRemainder()其实很相似,divide()是单纯的除法,divideAndRemainder()是一个数组,
		//类似于带余除法,一个数组来记录商和余数的值
		//这个数组也是BigInteger的
		//我举个例子
		//比如BigInteger[] bigInteger = test_a.divideAndRemainder(test_b);
	}
}

然后就没了,感觉一般我暂时会用的就是这些
这里面有很多的java包的详细讲解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值