参考:html
http://www.javashuo.com/article/p-qtcllgbq-hs.htmlide
http://www.javashuo.com/article/p-xfizplvg-hv.htmlspa
(double保留两位小数: System.out.println(String.format("%.2f",s));)code
1,大数的输入。orm
Scanner input = new Scanner(System.in); BigInteger a = input.nextBigInteger();
2,字符串转大数。htm
String s = "12345678987654321";
BigInteger a = new BigInteger(s);
BigInteger b =BigInteger.valueOf(s,10);//将字符串转换成10进制的大数
3,数字转大数。blog
int a =123456; BigInteger a = BigInteger.valueOf(a);
4,大数的四则运算。ip
a.add(b) //求a+b 加法 a.subtract(b) //求a-b 减法 a.divide(b) //求a/b 除法 a.multiply(b) //求a*b 乘法
5,其余运算。字符串
a.mod(b) //求余数即a%b a.gcd(b) //求最大公约数 a.max(b) //求最大值 a.min(b) //求最小值 a.pow(b) //求a^b的大数
a.toString().length(); //求大数的长度get
6:留个坑,大数的快慢如何呢?