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

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

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

  • isProbablePrime() method is used to check whether this BigInteger is probable prime or not.

    isProbablePrime()方法用于检查此BigInteger是否为可能的素数。

  • isProbablePrime() 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.

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

  • isProbablePrime() method does not throw an exception at the time of checking probable prime.

    在检查可能的素数时, isProbablePrime()方法不会引发异常。

Syntax:

句法:

    public boolean isProbablePrime(int probability);

Parameter(s):

参数:

  • int probability – represents the probability of being prime when probability <= 0.

    整数概率 –表示当概率<= 0时成为素数的概率。

Return value:

返回值:

The return type of this method is boolean, it returns true when this BigInteger is probably prime otherwise it returns false.

此方法的返回类型为boolean ,当此BigInteger可能为素数时返回true,否则返回false。

Example:

例:

// Java program to demonstrate the example
// of boolean isProbablePrime(int probability) method  of BigInteger
import java.math.*;
public class IsProbablePrimeOfBI {public static void main(String args[]) {// Initialize two variables str1 and str2
String str1 = "13";
String str2 = "6";
// Initialize two BigInteger objects
BigInteger b_int1 = new BigInteger(str1);
BigInteger b_int2 = new BigInteger(str2);
// checks whether this BigInteger
// b_int1 value is prime or not , here the
// value of b_int1 is 13 so it returns true
// because 13 is prime
boolean status = b_int1.isProbablePrime(2);
System.out.println("b_int1: " + b_int1);
System.out.println("b_int1.isProbablePrime(2): " + status);
System.out.println();
// checks whether this BigInteger
// b_int2 value is prime or not , here the
// value of b_int2 is 6 so it returns false
// because 6 is not prime (i.e. composite)
status = b_int2.isProbablePrime(2);
System.out.println("b_int2: " + b_int2);
System.out.println("b_int2.isProbablePrime(1): " + status);
System.out.println();
// checks whether this BigInteger
// b_int2 value is prime or not , here the
// value of b_int2 is 6 so it returns true
// because 6 is not prime (i.e. composite) but
// the given parameter value is -2 i.e. < 0 and
// when the given parameter value <=0 so it
// returns true even the value of b_int2 is composite
status = b_int2.isProbablePrime(-2);
System.out.println("b_int2: " + b_int2);
System.out.println("b_int2.isProbablePrime(-2): " + status);
}
}

Output

输出量

b_int1: 13
b_int1.isProbablePrime(2): trueb_int2: 6
b_int2.isProbablePrime(1): falseb_int2: 6
b_int2.isProbablePrime(-2): true

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

Java BigInteger类| isProbablePrime()方法与示例相关推荐

  1. java annotation class,Java Class类 isAnnotation()方法及示例

    Class类isAnnotation()方法isAnnotation()方法在java.lang包中可用. isAnnotation()方法用于检查此Class对象是否表示注释类型. isAnnota ...

  2. java字符类型的返回值,Java字符类isWhitespace()方法及示例

    Character 类isWhitespace()法isWhitespace()方法在java.lang包中可用. isWhitespace()方法用于检查给定的char值是否为空格,但是它包含空格中 ...

  3. Java BigInteger类| 带示例的shiftLeft()方法

    BigInteger类shiftLeft()方法 (BigInteger Class shiftLeft() method) shiftLeft() method is available in ja ...

  4. Java BigInteger类| modInverse()方法与示例

    BigInteger类modInverse()方法 (BigInteger Class modInverse() method) modInverse() method is available in ...

  5. Java BigInteger类| and()方法与示例

    BigInteger类和()方法 (BigInteger Class and() method) and() method is available in java.math package. and ...

  6. Java BigInteger类| 带有示例的减去()方法

    BigInteger类减去()方法 (BigInteger Class subtract() method) subtract() method is available in java.math p ...

  7. Java BigInteger类| toByteArray()方法与示例

    BigInteger类testBit()方法 (BigInteger Class testBit() method) testBit() method is available in java.mat ...

  8. Java BigInteger类| nextProbablePrime()方法与示例

    BigInteger类nextProbablePrime()方法 (BigInteger Class nextProbablePrime() method) nextProbablePrime() m ...

  9. Java BigInteger类| hashCode()方法与示例

    BigInteger类hashCode()方法 (BigInteger Class hashCode() method) hashCode() method is available in java. ...

最新文章

  1. Python使用matplotlib可视化斜率图、对比同一数据对象前后(before、after)两个状态的差异(Slope Chart)
  2. SAP WM 通过2-Step Picking创建的TO之间的关联关系
  3. 一种简易实现磁悬浮吊坠方案
  4. “365算法每日学计划”:05打卡-图解冒泡排序(多解法)
  5. Mr. Main and Windmills 模拟,计算几何(昆明)
  6. java 反转链表、合并链表
  7. 出现字迹模糊迹象_改变迹象:如何使用动态编程解决竞争性编程问题
  8. h5 storage事件监听
  9. Matlab绘图添加直角坐标轴
  10. ScrollView嵌套StackView提示需要宽度和高度限制
  11. 安全小测试:介绍一个简单web安全知识测试的网站
  12. 关于header('location:url')的一些说明,php缓冲区
  13. python DataFrame获取行数、列数、索引及第几行第几列的值
  14. 【项目篇- 项目团队部分怎么写、如何作图?(两千字图文总结建议)】创新创业竞赛项目计划书、新苗国创(大创)申报书、挑战杯创业计划竞赛
  15. PHP手机网店管理系统
  16. Biopython -- SeqRecord
  17. mysqldump --set-gtid-purged=OFF
  18. java js css 压缩工具_JS/CSS压缩工具(YUI Compressor)使用方法
  19. 摘抄部分经典励志语录: 送给所有心怀梦想的人们
  20. 三个字母的单词颠倒也是单词_世界上最强大的两个字母的单词

热门文章

  1. Linux配置本地yum源(RHEL8)
  2. JAVA服务器没回应_Java如何面对无服务器的挑战?
  3. 猫哥教你写爬虫 005--数据类型转换-小作业
  4. 一张图理解JS的原型(prototype、_proto_、constructor的三角关系)
  5. 从流程的自动化中获得最大价值的10种方式
  6. SQL Server 执行计划利用统计信息对数据行的预估原理二(为什么复合索引列顺序会影响到执行计划对数据行的预估)...
  7. Ajax实践之用户是否存在
  8. svn的使用(Mac)
  9. 转: 加快Android编译速度
  10. [Python]网络爬虫(七):Python中的正则表达式教程(转)