#Need help with why it's not printing correctly

15 messages · Page 1 of 1 (latest)

shy dawn
#
public static boolean isPrime(int value)
    {
        boolean isPrime = true;
        for(int i = 2; i < value; i++){
            if(value % i == 0){
                return false;
            }
            else{
                return true;
            }
        }
        return isPrime;
    }
topaz matrixBOT
#

This post has been reserved for your question.

Hey @shy dawn! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

brisk nymph
#

this method will always return false

shy dawn
#

Why

brisk nymph
#

because the last value of i will be equal to the value and the method will return false

shy dawn
#

alright so lemme edit it

#

there

#

I think thats fixes it

brisk nymph
#

it should

shy dawn
#

wait no it doesn't

brisk nymph
#

oh yeah remove the else

shy dawn
#

nah it doesnt bc it says 9 and 12 are primes

brisk nymph
shy dawn
#

ok thanks