zoukankan      html  css  js  c++  java
  • BigInteger类

    当一个数字非常大时,则肯定无法使用基本类型接受,所以使用了BigInteger类。

    BigInteger类表示是大整数类,定义在java.math包中,如果在操作时一个整型数据已经超过了整数的最大类型长度long,数据无法装入,此时可以使用BigInteger类进行操作。

    //=================================================
    // File Name       :	BigInteger_demo
    //------------------------------------------------------------------------------
    // Author          :	Common
    
    import java.math.BigInteger;
    
    
    //主类
    //Function        : 	BigInteger_demo
    public class BigInteger_demo {
    
    	public static void main(String[] args) {
    		// TODO 自动生成的方法存根
    		BigInteger bi1 = new BigInteger("123456789");		//定义BigInteger对象
    		BigInteger bi2 = new BigInteger("987654321");		//定义BigInteger对象
    		System.out.println("加法操作:"+bi2.add(bi1));		//加法操作
    		System.out.println("减法操作:"+bi2.subtract(bi1));		//减法操作
    		System.out.println("乘法操作:"+bi2.multiply(bi1));		//乘法操作
    		System.out.println("除法操作:"+bi2.divide(bi1));		//除法操作
    		System.out.println("最大值:"+bi2.max(bi1));		//最大值
    		System.out.println("最小值:"+bi2.min(bi1));		//最小值
    		
    		BigInteger result[] = bi2.divideAndRemainder(bi1);		//除法操作
    		System.out.println("商是:"+ result[0]+"余数是:"+result[1]);		
    	}
    
    }
    
  • 相关阅读:
    c#命名空间
    MUTC 2 B Meeting point1 二分
    高斯消元模板
    MUTC 2 C Meeting point2 切比雪夫距离orz
    MUTC 2 E Save the dwarfs DP?
    Uva 10859 Placing Lampposts 树形dp
    Uva 11552 Fewest Flops 字符串dp
    Uva 10891 Game of Sum dp博弈
    MUTC 2 D Matrix 并查集
    Uva 1456 Cellular Network 概率dp
  • 原文地址:https://www.cnblogs.com/tonglin0325/p/5269776.html
Copyright © 2011-2022 走看看