Display Prime Numbers in Java

This post shows how you can generate and display prime numbers in Java in the given range.

A number is a prime number if can be divided either by 1 or by the number itself. So every number with in the given range has to be divided starting from 2 till number/2 in the loop. You only need to run your loop from 2 to N/2 (where N is the passed number), reason being no number is completely divisible by a number more than its half.

Java code to display prime numbers within the given range


That’s all for the topic Display Prime Numbers in Java. If something is missing or you have something to share about the topic please write a comment.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.