java big number learning

import java.math.*;
import java.util. *;

public class study {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		BigInteger a, b;
		
		while(cin.hasNext()) { //Read in a loop until the end of the file
			a = cin.nextBigInteger();
			b = cin.nextBigInteger();
			System.out.println(a.add(b)); // 加
			System.out.println(a.subtract(b)); //减
			System.out.println(a.multiply(b)); // 乘
			System.out.println(a.divide(b)); // 除
			System.out.println(a.remainder(b)); //取模
			
			// big integer comparison
			if (a.compareTo(b) == 0) System.out.println("a == b");
			else if (a.compareTo(b) > 0) System.out.println("a > b");
			else if (a.compareTo(b) < 0) System.out.println("a < b");
			
			// big integer absolute value
			System.out.println(a.abs()); //The absolute value of the large integer a
			
			// powers of large integers
			int p = 10;
			System.out.println(a.pow(p)); //The p-th power of the large integer a
			
			//Return the string represented by the big integer decimal
			System.out.println(a.toString());
			
			//Return the string representation of the big integer k-ary
			int k = 8;
			System.out.print(a.toString(k));
		}
	}

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325225006&siteId=291194637