Prime number program in Java

Prime number program in Java

A number is said to be a prime number if it is greater than 1 and is divisible only by 1 and itself. For example the number 2 is divisible by 1 and 2 only. If you take 4 it is divisible by 1, 2 and 4. Hence 4 is not a prime number.

Write a program to check if the given number is prime or not (or) write a program to display Prime numbers from 1 to n (or) write a program to display n prime numbers are important Java interview questions. Let us see the program for these.

Hope you find these programs useful. If there is any error in the code let me know.

 

The following two tabs change content below.
Working as a Java developer since 2010. Passionate about programming in Java. I am a part time blogger.

Add Comment

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