Java 大数(整数+浮点数) 基本函数

 

 

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
    
    public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            
            BigInteger num1 = cin.nextBigInteger();
            BigInteger num2 = cin.nextBigInteger();
            
            System.out.println(num1.add(num2));
            System.out.println(num1.subtract(num2));
            System.out.println(num1.multiply(num2));
            System.out.println(num1.divide(num2));
            System.out.println(num1.mod(num2));
            System.out.println(num1.gcd(num2));
            System.out.println(num1.abs());
            System.out.println(num1.negate());
            System.out.println(num1.max(num2));
            System.out.println(num1.min(num2));
            System.out.println(num1.equals(num2));
            
            BigDecimal num3 = cin.nextBigDecimal();
            BigDecimal num4 = cin.nextBigDecimal();
            
            System.out.println(num3.add(num4));
            System.out.println(num3.subtract(num4));
            System.out.println(num3.multiply(num4));
            System.out.println(num3.divide(num4,10,BigDecimal.ROUND_HALF_DOWN));
            System.out.println(num3.abs());
            System.out.println(num3.negate());
            System.out.println(num3.max(num4));
            System.out.println(num3.min(num4));
            System.out.println(num3.equals(num4));            
            System.out.println(num3.compareTo(num4));
            
        }
}

 

posted @ 2018-03-20 11:46  Roni_i  阅读(271)  评论(0编辑  收藏  举报