JAVA大数运算
java大数是个好东西,用起来方便,代码短.
代码如下:
import java.util.*; import java.math.*; public class Main { public static void main(String args[]) { 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)); //取模 System.out.println(a.abs()); //绝对值 System.out.println(a.pow(10)); //x次幂 int bit = 16; System.out.println(a.toString(bit)); //转化为bit进制 } } }