LanQiaoTestCodes/大数.java

40 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package Course_Codes;
import java.math.BigInteger;
public class 大数 {
public static void main(String[] args) {
String num="FF";//num当作16进制那么对应的就是10进制的255
System.out.println(BigInteger.ONE);
BigInteger a=new BigInteger("9527");
System.out.println("a:"+a);
//将num转化为二进制
BigInteger b=new BigInteger(num,16);
System.out.println("b的十六进制为"+b);
//将b转化为八进制
System.out.println("b的八进制为"+b.toString(8));
//将b转化为二进制
System.out.println("b的二进制为"+b.toString(2));
//a+b a.add(b)=9527+255
System.out.println("a+b="+a.add(b));
//a-b a.subtract(b)=9527-255 a的值没有变
System.out.println("a-b="+a.subtract(b));
//a*b
System.out.println("a*b="+a.multiply(b));
//a/b
System.out.println("a/b="+a.divide(b));
//a%b
System.out.println("a%b="+a.mod(b));
//a b的最大公约数
System.out.println("a b的最大公约数"+a.gcd(b));
//判断a是否为素数
System.out.println("a是否为素数"+a.isProbablePrime(10));
//a^b%p
BigInteger two=new BigInteger("2");
//10^2%13=9
System.out.println("10^2%13="+BigInteger.TEN.modPow(two, new BigInteger("13")));
}
}