Primes and how to find them

Report a typo

Using the code below and the debugger, find the greatest prime number that is smaller than 459.

class Main {
    public static void main(String[] args) {
        int greatestPrimeInRange = 2;
        for (int number = 2; number <= 1000; number++) {
            if (isPrime(number) && number > greatestPrimeInRange) {
                greatestPrimeInRange = number;
            }
        }
    }

    static boolean isPrime(int number) {
        for (int i = 2; i <= number / 2; i++) {
            if (number % i != 0) {
                continue;
            } else {
                return false;
            }
        }
        return true;
    }
}
Enter a number
___

Create a free account to access the full topic