java 大数的学习

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()) { //循环读入,到文件尾
			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)); //取模
			
			// 大整数比较
			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");
			
			//大整数绝对值
			System.out.println(a.abs()); //大整数a的绝对值
			
			//大整数的幂
			int p = 10;
			System.out.println(a.pow(p)); //大整数a的p次幂
			
			//返回大整数10进制表示的字符串
			System.out.println(a.toString());
			
			//返回大整数k进制的字符串表示
			int k = 8;
			System.out.print(a.toString(k));
			
			//大整数赋值操作
            BigInteger tem = BigInteger.valueOf(10);
			System.out.println(tem);
		}
	}

}

 

posted @ 2018-05-03 23:34  楼主好菜啊  阅读(173)  评论(0编辑  收藏  举报