Java BigInteger类| 带实例的splitAndRemainder()方法

BigInteger类divideAndRemainder()方法 (BigInteger Class divideAndRemainder() method)

  • divideAndRemainder() method is available in java.math package.

    splitAndRemainder()方法在java.math包中可用。

  • divideAndRemainder() method returns BigInteger array of 2 elements that contain quotient that is calculated by using (this BigInteger)/(BigInteger val) followed by the remainder that is calculated by using (this BigInteger) % (BigInteger val).

    splitAndRemainder()方法将返回由2个元素组成的BigInteger数组,其中包含使用(this BigInteger)/(BigInteger val)计算得出的商数,然后返回使用(this BigInteger)%(BigInteger val)计算得出的余数。

  • divideAndRemainder() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    splitAndRemainder()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • divideAndRemainder() method may throw an exception at the time of calculating the remainder.

    在计算余数时, divideAndRemainder()方法可能会引发异常。

    ArithmeticException: This exception may throw when the given parameter holds value 0.

    ArithmeticException:当给定参数的值为0时,可能引发此异常。

Syntax:

句法:

    public BigInteger[] divideAndRemainder(BigInteger val);

Parameter(s):

参数:

  • BigInteger val – represents the value by which this BigInteger is to be divided and generate remainder.

    BigInteger val –表示该BigInteger被除以并生成余数的值。

Return value:

返回值:

The return type of this method is BigInteger[], it returns an array of BigInteger of two element of "BigInteger" type and the quotient is calculated by using (this BigInteger)/ (BigInteger val) and the remainder is calculated by using (this BigInteger) % (BigInteger val).

此方法的返回类型为BigInteger [] ,它返回两个由BigInteger类型组成的元素的BigInteger数组,商是使用(this BigInteger)/(BigInteger val)计算的,余数是使用(this BigInteger)%(BigInteger val)。

Example:

例:

// Java program to demonstrate the example 
// of divideAndRemainder(BigInteger val)  method of BigInteger
import java.math.*;
public class DivideAndRemainderOfBI {
public static void main(String args[]) {
// Initialize two variables divi, divisr
String divi = "120";
String divisr = "4";
// Initialize two BigInteger objects 
BigInteger b_int1 = new BigInteger(divi);
BigInteger b_int2 = new BigInteger(divisr);
// Display b_int1 and b_int2
System.out.println("b_int1: " + b_int1);
System.out.println("b_int2: " + b_int2);
System.out.println("divideAndRemainder(BigInteger): ");
// divides this BigInteger (b_int1) by the
// given BigInteger (b_int2) and return the BigInteger[]
// of two values (Quotient, Remainder)
BigInteger[] div_rem = b_int1.divideAndRemainder(b_int2);
System.out.println("Quotient div_rem[0]: " + div_rem[0]);
System.out.println("Remainder div_rem[1]: " + div_rem[1]);
}
}

Output

输出量

b_int1: 120
b_int2: 4
divideAndRemainder(BigInteger): 
Quotient div_rem[0]: 30
Remainder div_rem[1]: 0

翻译自: https://www.includehelp.com/java/biginteger-divideandremainder-method-with-example.aspx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542444.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SpringMVC Mybatis Shiro RestTemplate的实现客户端无状态验证及访问控制【转】

2019独角兽企业重金招聘Python工程师标准>>> A.首先需要搭建SpringMVCShiro环境 a1.pom.xml配置 spring: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId><version>4.1.0.RELEAS…

sql服务器默认密码_搭建一个DNS服务器,轻松实现域名解析内容分发,访问速度提高N倍...

DNS服务器&#xff0c;Domain Name Server&#xff0c;域名解析服务器&#xff0c;互联网上相互通信使用的是IP&#xff0c;但是IP是又长又臭又难记&#xff0c;所以创造了域名来解决IP难写难记的问题&#xff0c;记一个g.cn比203.208.50.127强过不知多少倍了。有了域名&#x…

在C ++ STL中使用string :: to_string()将数字转换为字符串

to_string() is a library function of <string> header, it is used to convert numeric value (number) to string. to_string()是<string>标头的库函数&#xff0c;用于将数值(数字)转换为字符串。 Syntax: 句法&#xff1a; string to_string(numberic_value…

门级建模

学习目标 学习Verilog提供的门级原语 理解门的实例引用、门的符号以及and/or&#xff0c;buf/not类型的门的真值表 学习如何根据电路的罗技图来生成Verilog描述 讲述门级设计中的上升、下降和关断延迟 解释门级设计中的最小、最大和典型延迟 1.门的类型 1.1与门&#xff08;and…

linux .net 控制台应用程序,VisualStudioCode创建的asp.net core控制台程序部署到linux

1、asp.net core控制台程序static void Main(string[] args){int times10;while(times>0){Console.WriteLine("Hello World!");times--;Thread.Sleep(1000);}}2、发布发布前&#xff0c;修改test2.csproj文件(项目名称为test2)Exenetcoreapp2.1centos.7-x64主要添…

数组长度属性以及JavaScript中的示例

JavaScript长度属性 (JavaScript length property) length property is used to get and set the length of an array in JavaScript. length属性用于获取和设置JavaScript中数组的长度。 Syntax to get the length of an array: 获取数组长度的语法&#xff1a; array_name.…

怎么挖linux内核的漏洞,linux内核漏洞分析实战看看专家是怎么一步步...-卓优商学院问答...

推荐回答Linux内核调试方法kdb&#xff1a;只能在汇编代码级进行调试&#xff1b;优点是不需要两台机器进行调试。gdb&#xff1a;在调试模块时缺少一些至关重要的功能&#xff0c;它可用来查看内核的运行情况&#xff0c;包括反汇编内核函数。kgdb&#xff1a;能很方便的在源码…

COGS182 [USACO Jan07] 均衡队形[RMQ]

182. [USACO Jan07] 均衡队形 ★★ 输入文件&#xff1a;lineup.in 输出文件&#xff1a;lineup.out 简单对比时间限制&#xff1a;4 s 内存限制&#xff1a;128 MB 题目描述 农夫约翰的 N (1 ≤ N ≤ 50,000) 头奶牛&#xff0c;每天挤奶时总会按同样的顺序站好。一日…

string中concat_JavaScript中带示例的String concat()方法

string中concat字符串concat()方法 (String concat() Method) concat() is a string method in JavaScript, it is used to concatenate (join) two or more strings and returns a new joined string. concat()是JavaScript中的字符串方法&#xff0c;用于连接(联接)两个或多个…

linux全自动备份网站到百度云盘,Linux定时备份数据到百度云盘(示例代码)

导读&#xff1a;如今的百度云盘免费容量都是2T了&#xff0c;即使把电脑上所有的东东都放上去&#xff0c;也还有大把的剩余空间。对于站长来说&#xff0c;是完全可以充分利用这些硬盘空间的&#xff0c;现在我们就用百度云盘来备份Linux服务器上的数据。一直在想&#xff0c…

python dict底层实现_dict实现原理和哈希表

dict底层实现在Python中&#xff0c;字典是依靠散列表或说哈希表(Hash Table)进行实现的&#xff0c;使用开放地址法解决冲突。所以其查找的时间复杂度会是O(1)&#xff0c;下文会具体讲解哈希表的工作原理和解决冲突时的具体方法。也就是说&#xff0c;字典也是一个数组&#…

网际控制报文协议icmp_网络中的ICMP(Internet控制消息协议)

网际控制报文协议icmpICMP(Internet控制消息协议)简介 (Introduction to ICMP (Internet Control Message Protocol)) IP (Internet Protocol) is a network layer protocol. The responsibility of delivering data (Logical Addressing) to any network is done by the IP (I…

谈色

最近很苦恼&#xff0c;像是到了男人的生理期&#xff0c;或者说是类似动物的发情期&#xff0c;见到露长腿的女人总喜欢看。 其实我是并不喜欢这样盯着看&#xff0c;或许是男人的本色&#xff0c;十个男人九个色的本性&#xff0c;总是会不自觉的去偷看&#xff0c;更有甚者还…

linux系统怎样写单片机程序,单片机知识是Linux驱动开发的基础之一以及如何学单片机...

这是arm裸机1期加强版第1课第2、3节课程的wiki文字版。为什么没前途也要学习单片机&#xff1f;因为它是个很好的入口。学习单片机可以让我们抛开复杂的软件结构&#xff0c;先掌握硬件操作&#xff0c;如&#xff1a;看原理图、芯片手册、写程序操作寄存器等。在上一节视频里&…

python教程循环语句_Python教程:关于Python 循环语句

Python 循环语句本章节将向大家介绍Python的循环语句&#xff0c;程序在一般情况下是按顺序执行的。编程语言提供了各种控制结构&#xff0c;允许更复杂的执行路径。循环语句允许我们执行一个语句或语句组多次&#xff0c;下面是在大多数编程语言中的循环语句的一般形式&#x…

math.pow int_Java Math类static int min(int i1,int i2)与示例

math.pow int数学类静态int min(int i1&#xff0c;int i2) (Math Class static int min(int i1 , int i2) ) This method is available in java.lang package. 此方法在java.lang包中可用。 This method is used to return the minimum one of both the given arguments or in…

bat 批处理 常用命令和乱码问题

为什么80%的码农都做不了架构师&#xff1f;>>> rem echo off ECHO OFF XCOPY E:\test.bat D:\ IF ERRORLEVEL 1 ECHO 文件拷贝Failure IF ERRORLEVEL 0 ECHO 文件拷贝Success :start set /p first"1记事本,2远程:" if %first% LEQ 2 (IF %first% …

SuperMap iServer发布的ArcGIS REST 地图服务如何通过ArcGIS API加载

作者&#xff1a;yx 文章目录 一、发布服务二、代码加载三、结果展示 一、发布服务 SuperMap iServer支持将地图发布为ArcGIS REST地图服务&#xff0c;您可以在发布服务时直接勾选ArcGIS REST地图服务&#xff0c;如下图所示&#xff1a; 也可以在已发布的地图服务中&#x…

c语言中的运算符及其含义_按位运算符及其在C语言中与Example一起使用

c语言中的运算符及其含义1)&#xff06;(按位与) (1) & (bitwise AND)) It does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. 它对两个数字的每一位进行“与”运算。 仅当两个位均为1时&#xff0c;AND的结果才为1。 Example: 例&…