answersLogoWhite

0

Take each number between the limits.

Divide it by every number from 2 to (number - 1). If it is divisible by any of the numbers, it is NOT a prime. Otherwise, it IS a prime.

In Java, that would be something like this:

int factor;

for (int number = lowerLimit; number <= upperLimit; number++)

{

for (factor = 2; number % factor != 0; factor++)

; // No statement in the for loop

if (factor == number) System.out.println(number);

}

In other words, look for the first factor; if that is the number itself, the number is a Prime number.

More efficient alternatives are possible; for example, it is enough to check only factors up to the square root of the number. For very large numbers, even this is inefficient; better methods are known, but they are more complicated.

User Avatar

Wiki User

14y ago

What else can I help you with?