Java大整數的處理
阿新 • • 發佈:2018-11-08
大整數的方法返回的不是一個字串,而是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!"); } } }