Java大整数的处理

大整数的方法返回的不是一个字符串,而是this val 

如果出现连续大整数处理,就需要把它变成字符串

方法参考下面代码:

import java.math.BigInteger;
import java.util.Scanner;

public class Wn {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
//        System.out.println(n);
        
        BigInteger fif = new BigInteger("0");
        BigInteger min = new BigInteger("0");
        
        for (int i = 0; i < n; i++) {
            String qq = sc.nextInt()+"";
            String vv = sc.nextInt()+"";
            
            BigInteger q = new BigInteger(qq);
            BigInteger v = new BigInteger(vv);
            BigInteger tt = new BigInteger(q.subtract(v)+"");
            fif = new BigInteger(fif.add(tt)+"");
        }
        
        if(fif.compareTo(min)==-1) {
            System.out.println("A company will go bankruptcy!");
        }else {
            System.out.println("No company will go bankruptcy!");
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/-rainbow-/p/9824504.html