Home >Java >javaTutorial >Simple code implementation of large number class in Java
This article mainly introduces relevant information about the simple implementation of large number classes in Java. Friends in need can refer to
Simple implementation of large number classes in Java
Large numbers in Java are quite easy to use and very convenient, so they are listed below for ready use
import java.math.*; import java.util.*; //基本使用如下: x = in.nextBigInteger(); y = in.nextBigInteger(); System.out.println(x.add(y)); //x+y; System.out.println(x.subtract(y)); //x-y; System.out.println(x.multiply(y)); // x*y; System.out.println(x.remainder(y)); // x%y; System.out.println(x.abs()); // x的绝对值; System.out.println(x.compareTo(y)==0); //x和y进行比较 System.out.println(x.toString(2)); // 转化为 x 的 n进制; x=BigInteger.ONE; //对x进行赋值 x=BigInteger.valueOf(5);// 对x进行赋值,使用的是long/int 类型数据 System.out.println(x);
The above is the detailed content of Simple code implementation of large number class in Java. For more information, please follow other related articles on the PHP Chinese website!