功能' spd'用于查找整数y的最小素数。 但是,当我运行代码时,无论' y'是,返回值始终为0.
public static BigInteger spd (int y) {
ArrayList<BigInteger> primes = new ArrayList<BigInteger>();
int retval;
int Nth_prime = 10000;
BigInteger getn;
BigInteger y2 = BigInteger.valueOf(y);
BigInteger TWO = new BigInteger("2");
BigInteger bi = new BigInteger("1");
primes.add(TWO);
int i = 1;
while (i < Nth_prime) {
bi = bi.add(TWO);
if (bi.isProbablePrime(40)) {
i++;
primes.add(bi);
}
}
BigInteger zero = new BigInteger ("0");
BigInteger ret;
BigInteger one = new BigInteger ("1");
for (int n = 0; n < y2.intValue(); n++) {
if (y2.mod(primes.get(n)).equals(zero)) {
retval = primes.get(n).intValue();
}
}
BigInteger returning = BigInteger.valueOf(retval);
return returning;
}
答案 0 :(得分:1)
这是初始化代码和一些重构代码:
class example {
private $something = "something";
public function myFunction($a = null)
{
if($a === null)
$a = $this->something;
// more code goes here
return $a;
}
}
$test = new example();
print $test->myFunction();
// prints "something"
print $test->myFunction("hello");
// prints "hello"