mardi 4 juin 2019

For the Java BigInteger Class, is there a way to define an if-statement with multiple conditions, seperated by logical operators?

Here is a method in Java which will be producing an ArrayList containing the first 100,000,000th fibonacci numbers, such that none of these fibonacci numbers are divisible by any smaller square number.

As a result, the BigInteger Java class is being implemented to handle numbers of an exceptionally large order.

It has been discovered that the use of logical operators such as && and || do not work with the BigInteger class when writing an if-statement as demonstrated in the code below.

Comments have been removed from the code for ease of reading on this page.

Your contributions are much appreciated.

public ArrayList<BigInteger> squareFree () {
    index = 0;
    fibValues_noSqr = fibValues;
    ArrayList<BigInteger> squares = new ArrayList<BigInteger>();

    int sqrScan;

    for (index = 0; index < fibValues_noSqr.size(); index++) {
        squares.add(BigInteger.valueOf(powerOf(index + 2, 2)));
    }

    for (index = 0; index < fibValues_noSqr.size(); index++) {
        for (sqrScan = 0; sqrScan < fibValues_noSqr.size(); sqrScan++) {
            if (squares.get(index).compareTo(fibValues_noSqr.get(sqrScan)) < 0 || squares.get(index).equals(fibValues_noSqr.get(sqrScan)) && fibValues_noSqr.get(sqrScan).remainder(squares.get(index))) {

                fibValues_noSqr.remove(sqrScan);
            }
        }
    }
}

The following error is revealed by Java in this scenario

The operator && is undefined for the argument type(s) boolean, BigInteger

Aucun commentaire:

Enregistrer un commentaire