You are viewing a single comment's thread from:
RE: Java program -5: Write a program which show the display of 15 prime number.
It’s a good post, but you could be more thoughtful on the inner loop. You could use a step-size of at least 2. Or if the number is larger than 3, print 3 and use a step-size of 3. Cause the primes cannot be any multiples of those numbers. In fact you just have to check if they are divisible by smaller prime numbers. If not, it is a new prime. That’s a much more efficient way. But your way is also okay for little numbers.