日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

ACM与Java -- 大整数类的常用函数一览表

發(fā)布時(shí)間:2023/12/10 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ACM与Java -- 大整数类的常用函数一览表 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
BigInteger abs()?
此方法返回一個(gè)BigInteger,其值是此BigInteger的絕對(duì)值。
2BigInteger add(BigInteger val)
此方法返回一個(gè)BigInteger,其值是(this + val).
3BigInteger and(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this & val).
4BigInteger andNot(BigInteger val)?
此方法返回一個(gè)BigInteger,其值是 (this & ~val).
5int bitCount()
此方法返回此BigInteger的二進(jìn)制補(bǔ)碼表示的位,從符號(hào)位不同的數(shù)字。
6int bitLength()?
此方法返回位在此BigInteger的最小的二進(jìn)制補(bǔ)碼表示的數(shù),不包括符號(hào)位。
7BigInteger clearBit(int n)
此方法返回一個(gè)BigInteger,其值相當(dāng)于此BigInteger與指定位清零。
8int compareTo(BigInteger val)
此方法比較此BigInteger與指定的BigInteger。
9BigInteger divide(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this / val).
10BigInteger[ ] divideAndRemainder(BigInteger val)
此方法返回一個(gè)包含兩個(gè)BigIntegers:(this / val) 和?(this % val),其次是一個(gè)數(shù)組。
11double doubleValue()
此方法此BigInteger轉(zhuǎn)換為雙精度double。?
12boolean equals(Object x)
此方法比較此BigInteger與指定對(duì)象是否相等。
13BigInteger flipBit(int n)
此方法返回一個(gè)BigInteger,其值相當(dāng)于此BigInteger與指定位翻轉(zhuǎn)。
14float floatValue()
此方法將BigInteger轉(zhuǎn)換為float。
15BigInteger gcd(BigInteger val)?
此方法返回一個(gè)BigInteger,其值是絕對(duì)值的最大公約數(shù):abs(this)?和abs(val)。
16int getLowestSetBit()
此方法返回最右邊的(最低階)的索引在此BigInteger1比特(零比特的數(shù)量,以最右側(cè)的1位的右側(cè))。
17int hashCode()
此方法返回此BigInteger的哈希代碼。
18int intValue()
此方法此BigInteger轉(zhuǎn)換為int。
19boolean isProbablePrime(int certainty)
此方法返回true,如果此BigInteger是素?cái)?shù),其絕對(duì)復(fù)合數(shù)則返回false。
20long longValue()
些方法將BigInteger轉(zhuǎn)換為long。
21BigInteger max(BigInteger val)
此方法返回此BigInteger和val的最大值。
22BigInteger min(BigInteger val)
此方法返回此BigInteger和val的最小值。
23BigInteger mod(BigInteger m)
此方法返回一個(gè)BigInteger,其值是(this mod m).
24BigInteger modInverse(BigInteger m)
此方法返回一個(gè)BigInteger,其值是 (this-1?mod m).
25BigInteger modPow(BigInteger exponent, BigInteger m)
此方法返回一個(gè)BigInteger,其值是 (thisexponent?mod m).
26BigInteger multiply(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this * val).
27BigInteger negate()
此方法返回一個(gè)BigInteger,其值是 (-this).
28BigInteger nextProbablePrime()?
此方法返回一個(gè)整數(shù)大于該BigInteger的可能是素?cái)?shù)。
29BigInteger not()
此方法返回一個(gè)BigInteger,其值是 (~this).
30BigInteger or(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this | val).
31BigInteger pow(int exponent)
此方法返回一個(gè)BigInteger,其值是(thisexponent).
32static BigInteger probablePrime(int bitLength, Random rnd)
此方法返回一個(gè)正BigInteger的可能是素?cái)?shù),以指定的bitLength。
33BigInteger remainder(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this % val).
34BigInteger setBit(int n)
此方法返回一個(gè)BigInteger,其值相當(dāng)于此BigInteger與指定的位設(shè)置。
35BigInteger shiftLeft(int n)
此方法返回一個(gè)BigInteger,其值是 (this << n).
36BigInteger shiftRight(int n)
此方法返回一個(gè)BigInteger,其值是 (this >> n).
37int signum()?
This method returns the signum function of this BigInteger.
38BigInteger subtract(BigInteger val)
此方法返回一個(gè)BigInteger,其值是 (this - val).
39boolean testBit(int n)
此方法返回當(dāng)且僅當(dāng)所指定的位被設(shè)置為真。
40byte[ ] toByteArray()
此方法返回一個(gè)包含此BigInteger的二進(jìn)制補(bǔ)碼表示的字節(jié)數(shù)組。
41String toString()?
此方法返回此BigInteger的十進(jìn)制字符串表示形式。
42String toString(int radix)?
此方法返回在給定的基數(shù)以BigInteger的字符串表示形式。
43static BigInteger valueOf(long val)
此方法返回一個(gè)BigInteger,其值等于指定long。
44BigInteger xor(BigInteger val)?
此方法返回一個(gè)BigInteger,其值是 (this ^ val).

詳情https://www.yiibai.com/java/math/java_math_bigdecimal.html

大整數(shù)類:?

import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner;public class q {public static void main(String[] args) {BigInteger a = BigInteger.valueOf(20);BigInteger b = BigInteger.valueOf(450);System.out.println(a);System.out.println(b);//加法System.out.println(a.add(b));System.out.println(a.add(a));System.out.println(a.add(b).add(b));//減法System.out.println(a.subtract(a));System.out.println(a.subtract(b));System.out.println(b.subtract(a).subtract(a));//乘法System.out.println(a.multiply(a));System.out.println(a.multiply(b));System.out.println(a.multiply(b).multiply(b));//除法System.out.println(a.divide(a));System.out.println(a.divide(b));//10/2000=0System.out.println(b.divide(a));System.out.println(b.divide(a).divide(a));//取模BigInteger mod = BigInteger.valueOf(3);System.out.println(b.mod(mod));} }

大數(shù):

構(gòu)造器描述?

BigDecimal(int) ? ? ? 創(chuàng)建一個(gè)具有參數(shù)所指定整數(shù)值的對(duì)象。?

BigDecimal(double) 創(chuàng)建一個(gè)具有參數(shù)所指定雙精度值的對(duì)象。?

BigDecimal(long) ? ?創(chuàng)建一個(gè)具有參數(shù)所指定長(zhǎng)整數(shù)值的對(duì)象。?

BigDecimal(String) 創(chuàng)建一個(gè)具有參數(shù)所指定以字符串表示的數(shù)值的對(duì)象。

方法描述?

add(BigDecimal) ? ? ? ?BigDecimal對(duì)象中的值相加,然后返回這個(gè)對(duì)象。?

subtract(BigDecimal) BigDecimal對(duì)象中的值相減,然后返回這個(gè)對(duì)象。?

multiply(BigDecimal) ?BigDecimal對(duì)象中的值相乘,然后返回這個(gè)對(duì)象。?

divide(BigDecimal) ? ? BigDecimal對(duì)象中的值相除,然后返回這個(gè)對(duì)象。?

toString() ? ? ? ? ? ? ? ?將BigDecimal對(duì)象的數(shù)值轉(zhuǎn)換成字符串。? (一般都用toPlainString())

doubleValue() ? ? ? ? ?將BigDecimal對(duì)象中的值以雙精度數(shù)返回。?

floatValue() ? ? ? ? ? ? 將BigDecimal對(duì)象中的值以單精度數(shù)返回。?

longValue() ? ? ? ? ? ? 將BigDecimal對(duì)象中的值以長(zhǎng)整數(shù)返回。?

intValue() ? ? ? ? ? ? ? 將BigDecimal對(duì)象中的值以整數(shù)返回。?

常用搭配:stripTrailingZeros().toPlainString(); 在保證數(shù)值不變的前提下,去除后綴0,并且保留十進(jìn)制的特性。 import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner;public class q {public static void main(String[] args) {//如果加引號(hào)了或者是直接控制臺(tái)讀入的,默認(rèn)使用了string的構(gòu)造器,否則相當(dāng)于是intBigDecimal a = new BigDecimal(10);BigDecimal b = new BigDecimal(10.5);BigDecimal c = new BigDecimal(123456789101222L);BigDecimal d = new BigDecimal("-123456.31");System.out.println(a);System.out.println(b);System.out.println(c);System.out.println(d);//四則運(yùn)算System.out.println(a.add(b).add(c).add(d));System.out.println(a.subtract(b).subtract(a));System.out.println(a.multiply(b).multiply(c));System.out.println(c.divide(a).divide(new BigDecimal(20)));System.out.println(d.divide(a));System.out.println(d.doubleValue());System.out.println(a.compareTo(a));// 0System.out.println(a.compareTo(b));// -1System.out.println(b.compareTo(a));// 1BigDecimal aa = new BigDecimal(10.00);BigDecimal bb = new BigDecimal(10.000);BigDecimal cc = new BigDecimal(200);String aa = di.stripTrailingZeros().toPlainString();System.out.println(aa.equals(aa));// true?System.out.println(aa.equals(bb));// true?System.out.println(aa.equals(cc));//false}}

保留位數(shù):

例如:1.將f1保留2位有效數(shù)字輸出2.將f1保留4位有效數(shù)字輸出1.System.out.println((double)(Math.round(f1*100)/100.0));2.System.out.println((double)(Math.round(sd3*100)/100.0));注意:若數(shù)據(jù)只有小數(shù)點(diǎn)后第n位為0,則保留到不為0的位;如3.14003保留1位結(jié)果:3.1保留2位結(jié)果:3.14保留3位結(jié)果:3.14保留4位結(jié)果:3.14保留5位結(jié)果:3.1400 例如:1.將f1保留2位有效數(shù)字輸出 2.將f1保留4位有效數(shù)字輸出 1.System.out.println((double) (Math.round(f1*100)/100.0)); 2.System.out.println((double) (Math.round(sd3*100)/100.0)); 注意:若數(shù)據(jù)只有小數(shù)點(diǎn)后第n位為0,則保留到不為0的位; 如 3.14003 保留1位結(jié)果:3.1 保留2位結(jié)果:3.14 保留3位結(jié)果:3.14 保留4位結(jié)果:3.14 保留5位結(jié)果:3.14003 另一種辦法: import java.text.DecimalFormat; DecimalFormat df2 = new DecimalFormat("###.00"); DecimalFormat df2 = new DecimalFormat("###.000"); System.out.println(df2.format(f1)); 第一個(gè)為2位,第二個(gè)為3位. 如 3.14003 保留1位結(jié)果:3.1 保留2位結(jié)果:3.14 保留3位結(jié)果:3.140 保留4位結(jié)果:3.1400 保留5位結(jié)果:3.14003

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的ACM与Java -- 大整数类的常用函数一览表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。