BigInteger详解
来源:互联网 发布:数据库sql种类 编辑:程序博客网 时间:2024/06/08 09:36
在用C或者C++处理大数时感觉非常麻烦,但是在Java中有两个类BigInteger和BigDecimal分别表示大整数类和大浮点数类,至于两个类的对象能表示最大范围不清楚,理论上能够表示无线大的数,只要计算机内存足够大。
这两个类都在java.math.*包中,因此每次必须在开头处引用该包。
Ⅰ基本函数:
1.valueOf(parament); 将参数转换为制定的类型
2.add(); 大整数相加
BigInteger a=new BigInteger(“23”);
BigInteger b=new BigInteger(“34”);
a.
3.subtract(); 相减
4.multiply(); 相乘
5.divide();
6.remainder(); 取余
7.pow();
8.gcd();
9.abs(); 绝对值
10.negate(); 取反数
11.mod(); a.mod(b)=a%b=a.remainder(b);
12.max(); min();
13.punlic int comareTo();
14.boolean equals(); 是否相等
15.BigInteger构造函数:
一般用到以下两种:
BigInteger(String val);
将指定字符串转换为十进制表示形式;
BigInteger(String val,int radix);
将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger
Ⅱ.基本常量:
A=BigInteger.ONE
B=BigInteger.TEN
C=BigInteger.ZERO
Ⅲ.基本操作
1.
用Scanner类定义对象进行控制台读入,Scanner类在java.util.*包中
Scanner cin=new Scanner(System.in);// 读入
while(cin.hasNext())
{
}
if( a.compareTo(b) == 0 ) System.out.println("a == b"); //大整数a==b
- BigInteger详解
- BigInteger详解
- BigInteger详解
- BigInteger详解
- BigInteger详解
- BigDecimal和BigInteger详解
- Java中BigInteger详解
- BigInteger 用法详解
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- BigInteger
- 4-18-1-使用指针交换数据、多线程参数传递、多线程通信、指针与数组
- 读书笔记:C++ primer 5th edition--chapter16.模板与泛型编程
- jsp中实现java程序片段动态生成表格内容
- Mysql配置主从复制
- 源码安装Python
- BigInteger详解
- 聪明的kk
- 大学里
- Android Studio问题汇总
- CSS3三角形的妙用
- 《JavaWeb实战开发经典》笔记——第五章
- PAT 乙级1003 我要通过
- 我的第一篇CSDN博客
- 绝世秘籍之GNU构建系统与Autotool概念分析