# Java Program to displaying prime numbers

By | October 12, 2018

In Previous post Check whether a number is prime or not we learnt how to check whether given number is prime number or not and this post is all about Java Program to displaying prime numbers

As we know that a number is a prime number if it is a natural number greater than 1 and it can be divided either by 1 or by the number itself. As example- 2, 3, 5, 7, 11, 13, 17,19,23..….

For checking if a number is prime or not you have to run a loop starting from 2 till number/2 to check if number has any divisor or not.

As example – If number is 10 then you just need to check till 5 (10/2) to see if it divides by any number or not. Same way if you have a number 25 you just need to check till 12(25/2) to see if it divides completely by any number or not. We’ll use the same concept/logic to write our java program to check for prime number.

#### Note: You should note that 0 and 1 are not prime numbers. We have number 2 is the only even prime number because all the other even numbers can be divided by 2.

Let’s write a Java Program to displaying prime numbers

Output of this program:

That’s all about Java Program to displaying prime numbers

You May Also Like:

If you have any feedback or suggestion please feel free to drop in blow comment box.