Dandy Dandy - 1 year ago 123
Java Question

BigInteger not increasing?

For some reason my

variable isn't increasing within the while-loop. Any reason as to why it's not doing so?

import java.math.*;

public static void main(String[] args) {

/* Variables */
BigInteger PQ = new BigInteger("17");
BigInteger E = new BigInteger("7");

BigInteger val = new BigInteger("2");

/* Find the PRIME factors of PQ */
while (PQ.compareTo(BigInteger.ONE) == 1) { // while the first value is greater
if (PQ.mod(val).equals(BigInteger.ZERO)) {
System.out.print(val + " ");
} else {

Answer Source

val.add(BigInteger.ONE) returns a new value. You do not assign it to anything:

val = val.add(BigInteger.ONE);

Class BigInteger

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download