M
M
Makaron30002021-06-30 14:10:38
Java
Makaron3000, 2021-06-30 14:10:38

Why does an int cannot be converted to java.math.BigInteger error pop up?

When using the method, it gives an error int cannot be converted to java.math.BigInteger, although I have translated BigInteger into Integer

public static String oddity(BigInteger n) {
        int n2 = n.intValue();
        int count = 0;
        for(int i = 1; i <= n2; i++){
            if(n2 % i == 0){
                count++;
            }
        }
        if(count % 2 == 0){
            return "even";
        }
        return "odd";
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Roo, 2021-06-30
@xez

Apparently, because instead of BigInteger you shove it into the int method

M
Makaron3000, 2021-06-30
@Makaron3000

and yes i tried that too, got the same error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question