BigInteger类的方法

BigInteger类的方法
 *    divide(BigInteger val)
            返回其值为 (this / val) 的 BigInteger。
          multiply(BigInteger val)
            返回其值为 (this * val) 的 BigInteger。
          subtract(BigInteger val)
            返回其值为 (this - val) 的 BigInteger。
          add(BigInteger val)
            返回其值为 (this + val) 的 BigInteger
         remainder(BigInteger val)
            返回其值为 (this % val) 的 BigInteger。
        divideAndRemainder(BigInteger val)
            返回包含 (this / val) 后跟 (this % val) 的两个 BigInteger 的数组。 返回值BigInteger[]

 1 package integer;
 2
 3 import java.math.BigInteger;
 4
 5 /**
 6  * BigInteger类的方法
 7  *         divide(BigInteger val)
 8           返回其值为 (this / val) 的 BigInteger。
 9           multiply(BigInteger val)
10           返回其值为 (this * val) 的 BigInteger。
11           subtract(BigInteger val)
12           返回其值为 (this - val) 的 BigInteger。
13           add(BigInteger val)
14           返回其值为 (this + val) 的 BigInteger
15          remainder(BigInteger val)
16           返回其值为 (this % val) 的 BigInteger。
17      divideAndRemainder(BigInteger val)
18           返回包含 (this / val) 后跟 (this % val) 的两个 BigInteger 的数组。 返回值BigInteger[]
19  * @author star
20  *
21  */
22 public class BigIntegerDemo {
23     public static void main(String[] args) {
24         String s = Integer.MAX_VALUE+"";//2147483647
25         System.out.println(s);
26
27         String s1 = Long.MAX_VALUE+"";//9223372036854775807
28         System.out.println(s1);
29
30         BigInteger big = new BigInteger("5344444444444444778815991");
31         BigInteger big2 = new BigInteger("5344444444599");
32         //运算
33         System.out.println(big.add(big2));
34         System.out.println(big.subtract(big2));
35         System.out.println(big.multiply(big2));
36          System.out.println(big.divide(big2));
37
38          //返回一个BigInteger[]数组
39          BigInteger b1 = new BigInteger("10");
40         BigInteger b2 = new BigInteger("2");
41         BigInteger[] res = b1.divideAndRemainder(b2);
42         System.out.println(res[0]);
43         System.out.println(res[1]);
44
45     }
46 }

BigInteger

原文地址:https://www.cnblogs.com/star521/p/8886305.html

时间: 2024-07-31 22:43:14

BigInteger类的方法的相关文章

Java基础系列9:BigInteger类和BigDecimal类

一 BigInteger类 当我们碰到需要处理一个很大的数字时,这时候肯定没法使用int和long.当然我们可以使用String来接收大数字,然后再采用拆分的方式来计算,不过这种方式很麻烦.因此在Java中为了解决这种问题,提供了BigInteger类.BigInteger类表示是大整数类,定义在java.math.*这个包中,如果操作的整数已经超过了整数的最大类型长度long,这时可以考虑使用BigInteger类来进行操作 常用方法的示例: package javase.base; impo

math类和biginteger类

Math类:这种工具类,一般不会创建对象,方法为静态方法,直接调用 package com.oracle.demo02; public class MathDemo { public static void main(String[] args) { // TODO Auto-generated method stub //绝对值 System.out.println(Math.abs(-99)); //向上取整 System.out.println(Math.ceil(12.2)); //向下

反射之获取类,方法等

1 反射之获取类      获取类有三种方法 public interface Person { public void sayHi(); }   public class Student  implements Person{ private String id; private String name; private int age; public int sex=1; //省去构造方法和get set方法 } Class c1 = Student.class; Class c2=Clas

【Android 工具类】经常使用工具类(方法)大全

收集经常使用的工具类或者方法: 1.获取手机分辨率 /** * 获取手机分辨率 */ public static String getDisplayMetrix(Context context) { if (Constant.Screen.SCREEN_WIDTH == 0 || Constant.Screen.SCREEN_HEIGHT == 0) { if (context != null) { int width = 0; int height = 0; SharedPreferences

PHP类和对象之定义类的方法

方法就是在类中的function,很多时候我们分不清方法与函数有什么差别,在面向过程的程序设计中function叫做函数,在面向对象中function则被称之为方法. 同属性一样,类的方法也具有public,protected 以及 private 的访问控制. 访问控制的关键字代表的意义为:public:公开的protected:受保护的private:私有的 我们可以这样定义方法: class Car { public function getName() { return '汽车'; }

c#类的方法表的建立和方法的调用

对于方法的调用,很是令我头疼,什么静态方法,实例方法,实例虚方法,这里查了很多资料,总结如下: 这里声明,我也是菜鸟,这里只讨论方法的调用相关的技术,属于个人理解,如有错误,请指正 思路: 1 clr在加载类型的过程中方法表是怎么样构建的? 2 在程序调用方法时是怎样确定使用哪个类型的方法表的? 3 在程序调用方法时是怎样确定方法在方法表中的位置的(位于方法表的第几个方法)? 一 .方法在方法表中的排列顺序: 继承的实例虚方法.实例虚方法.构造函数.静态方法.实例方法 方法表排列原则: 1 在类

java中常用的包、类、以及包中常用的类、方法、属性-----io包

由于最近有需要,所以下面是我整理的在开发中常用的包.类.以及包中常用的类.方法.属性:有需要的看看 java中常用的包.类.以及包中常用的类.方法.属性 常用的包 java.io.*; java.util.*; java.lang.*; java.math.*; java.sql.*; java.text.*; java.awt.*; javax.swing.*;   包名 接口 类 方法 属性 java.io.*; java.io.Serializable实现序列化 java.io.Buffe

dede数据库类使用方法

dede数据库类使用方法 $dsql dedecms的数据库操作类,非常实用,在二次开发中尤其重要,这个数据库操作类说明算是奉献给大家的小礼物了. 引入common.inc.php文件 1 require_once (dirname(__FILE__) . "/include/common.inc.php"); 获取一条记录的内容 1 2 $row = $dsql->GetOne("Select * From dede_* where id = $aid");

自定义类工厂方法

1.自定义工厂方法 什么是工厂方法(快速创建方法) 类工厂方法是一种用于分配.初始化实例并返回一个它自己的实例的类方法.类工厂方法很方便,因为它们允许您只使用一个步骤(而不是两个步骤)就能创建对象. 例如new 自定义类工厂方法的规范 (1)一定是+号开头 (2)返回值一般是instancetype类型 (3)方法名称以类名开头,首字母小写 示例 + (id)person; + (id)person { return [[Person alloc]init]; } + (id)personWit