BigInteger:可以让超过Integer范围内的数据进行运算
2016-08-04 09:27
573 查看
package cn.itcast_02;
import java.math.BigInteger;
/*
* public BigInteger add(BigInteger val):加
* public BigInteger subtract(BigInteger val):减
* public BigInteger multiply(BigInteger val):乘
* public BigInteger divide(BigInteger val):除
* public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
*/
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("100");
BigInteger bi2 = new BigInteger("50");
// public BigInteger add(BigInteger val):加
System.out.println("add:" + bi1.add(bi2));
// public BigInteger subtract(BigInteger val):加
System.out.println("subtract:" + bi1.subtract(bi2));
// public BigInteger multiply(BigInteger val):加
System.out.println("multiply:" + bi1.multiply(bi2));
// public BigInteger divide(BigInteger val):加
System.out.println("divide:" + bi1.divide(bi2));
// public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
BigInteger[] bis = bi1.divideAndRemainder(bi2);
System.out.println("商:" + bis[0]);
System.out.println("余数:" + bis[1]);
}
}
import java.math.BigInteger;
/*
* public BigInteger add(BigInteger val):加
* public BigInteger subtract(BigInteger val):减
* public BigInteger multiply(BigInteger val):乘
* public BigInteger divide(BigInteger val):除
* public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
*/
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger bi1 = new BigInteger("100");
BigInteger bi2 = new BigInteger("50");
// public BigInteger add(BigInteger val):加
System.out.println("add:" + bi1.add(bi2));
// public BigInteger subtract(BigInteger val):加
System.out.println("subtract:" + bi1.subtract(bi2));
// public BigInteger multiply(BigInteger val):加
System.out.println("multiply:" + bi1.multiply(bi2));
// public BigInteger divide(BigInteger val):加
System.out.println("divide:" + bi1.divide(bi2));
// public BigInteger[] divideAndRemainder(BigInteger val):返回商和余数的数组
BigInteger[] bis = bi1.divideAndRemainder(bi2);
System.out.println("商:" + bis[0]);
System.out.println("余数:" + bis[1]);
}
}
相关文章推荐
- JAVA学习笔记--final、finally、finalize的区别
- POJ1062——昂贵的聘礼
- C#集合
- 陶 谢楚余
- Beyond Local Search: Tracking Objects Everywhere with Instance-Specific Proposals
- POJ2225Asteroids![Depth first search]
- 表格等宽列
- 【Linux总结】Linux命令学习一
- C++中的delegate机制:现在网上可以找到的解决方案
- ZZULIOJ-1894-985的方格难题(BFS&规律&DP)
- 在终端里面显示图片
- 在终端里面显示图片
- 继承、封装、多态
- Mat, vector<point2f>,Iplimage等等常见类型转换
- jQuery 对动态生成元素进行事件绑定
- tornado同步和异步GET
- Codeforces 166A Rank List(二分)
- 根据base64转换成图片并上传服务器
- 各种品牌/组装电脑一键u盘启动快捷键表
- new Thread的弊端及Java四种线程池的使用