BigInteger和BigDecimal的基本用法

整型大數 BigInteger:java

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
       public static void main(String[] args) {
             Scanner scan=new Scanner(System.in);
             BigInteger aa =new BigInteger("100");
             BigInteger bb= new BigInteger("25");
             BigInteger sub=aa.subtract(bb); //大整數的減
             BigInteger add=aa.add(bb);      //大整數的加
             BigInteger mul=aa.multiply(bb); //大整數的乘
             BigInteger div=aa.divide(bb);   //大整數的除
             System.out.println(sub.toString());
             System.out.println(add.toString());
             System.out.println(mul.toString());
             System.out.println(div.toString());
    }
}

浮點型大數 BigDecimal 加減乘除用法 同BigIntegeride

相關文章
相關標籤/搜索