Scanner sc1 = new Scanner(System.in);
System.out.print("Enter prime p value up to 32 bits: ");
BigInteger p = sc1.nextBigInteger();
while(p.isProbablePrime(1) == false && p.compareTo(BigInteger.valueOf(2147483647)) == 1);
{
System.out.print("Sorry your p value must be a prime and up to 32bits! Please enter again: ");
p = sc1.nextBigInteger();
}
因此,我输入的值大于2147483647
,我的while
第一次工作,但第二次没有运行。
Enter prime p value up to 32 bits: 2147483659
Sorry your p value must be a prime and up to 32bits! Please enter again: 2147483659
Enter prime q value up to 32 bits:
不满足我的条件时,它会跳到我的q
值。
答案 0 :(得分:1)
尝试改用以下代码(例如,删除do / while):
Scanner sc1 = new Scanner(System.in);
System.out.print("Enter prime p value up to 32 bits: ");
BigInteger p = sc1.nextBigInteger();
while(!p.isProbablePrime(1) || p.compareTo(BigInteger.valueOf(2147483647)) == 1) {
System.out.print("Sorry your p value must be a prime and up to 32bits! Please enter again: ");
p = sc1.nextBigInteger();
}
答案 1 :(得分:0)
无论如何,DO循环将始终执行一次。 因此,您的子对象总是评估为false(因此循环停止)。 尝试这样设置
<?php
namespace dealspace_websocket;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class Chat implements MessageComponentInterface {
protected $clients;
public function __construct() {
//$this->clients = new \SplObjectStorage;
$this->clients = [];
}
public function onOpen(ConnectionInterface $conn) {
$cookiesArray = $conn->httpRequest->getHeader('Cookie');
}
}
那是
public final long c = 2147483647;
while(!p.isProbablePrime(1) || p.compareTo(BigInteger.valueOf(c)) == 1);
答案 2 :(得分:0)
可以使用吗?
public static void main(String[] args) {
Scanner sc1 = new Scanner(System.in);
System.out.print("Enter prime p value up to 32 bits: ");
BigInteger p = sc1.nextBigInteger();
while (!p.isProbablePrime(1) || p.compareTo(BigInteger.valueOf(2147483647)) > 0)) {
System.out.print("Sorry your p value must be a prime and up to 32bits! Please enter again: ");
sc1 = new Scanner(System.in);
p = sc1.nextBigInteger();
}
}