BigInteger类方法代码简介

BigInteger类方法代码 详解 简介

懒得做PPT了,直接写代码。

import java.math.BigInteger;
import java.util.Random;

public class Biginteger {
   
	public static void main(String[] args) {
   
		/** @实现 
		 * public class BigInteger extends Number implements Comparable<BigInteger>{
		 *     final int signum; 
		 *     final int[] mag; 
		 * }
		 */
		
		
		
		
		
		
		
		/** @范围测试  
		 * >10^83886081   test.txt: 80.01MB    time: 578174ms
		 * 
		 * BigInteger s = new BigInteger("10000000000"); 
		 * long t = System.currentTimeMillis(); 
		 * for(int i=0;i<1000000;i++){ 
		 * 		s = s.multiply(s); 
		 * 		System.out.println(s.toString().length());
		 * 		System.out.println(System.currentTimeMillis()-t); 
		 * }
		 */
		
		 
		
		
		
		

		/** 常量 
		 * @public static final BigInteger ZERO 
		 * @public static final BigInteger ONE
		 * public static final BigInteger TWO (jdk9) 
		 * public static final BigInteger TEN
		 */
		System.out.println("常数:" + BigInteger.ZERO + "," + BigInteger.ONE  + "," + BigInteger.TEN + '\n');

		
		
		
		
		
		
		
		/** 构造 
		 * @public BigInteger(String val)
		 * @public BigInteger(String val, int radix)
		 * public BigInteger(byte[] val) public BigInteger(int signum, byte[]magnitude) 
		 * public BigInteger(int bitLength, int certainty, Random rnd)
		 * public BigInteger(int numBits, Random rnd) public BigInteger(String val)
		 */
		// 使用字符串构造,默认为十进制。使用字符串构造需要注意数值必须为正
		System.out.println("字符串构造大数:" + new BigInteger("+123123123123123"));
		System.out.println("int等类型构造大数:" + new BigInteger(String.valueOf(-1234567890)));
		System.out.println("指定进制字符串构造大数:" + new BigInteger("ZZZZZZZ", 36));
		
		byte[] by = {
    15, 15 };
		// 00001111 00001111 -> 3855
		System.out.println("按位构造:" + new BigInteger(by));
		System.out.println("按位构造(有符号):" + new BigInteger(-1, by)
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猪猪侠的Laser_Cannon

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值