**Prime Number Program in Java:** This is a simple **Java program to find the prime number**. A prime number is a number which is greater than 1 and only divisible by 1 or itself.

In the below example, we have shared the **first 10 prime number **which you can test using below Java program to confirm the Prime number program in Java programming language.

1 | 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 |

In this program, I have taken `number`

as variable to hold the number which will be checked whether it is a prime number or not.

Copy the below java program and execute it with the help of Java compiler to print the prime number program in java with the output for your better under standing the concept of prime number.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | public class PrimeNumberExample{ public static void main(String args[]){ int i,m=0,flag=0; int number=11;//it is the number to be checked m=number/2; if(number==0||number==1){ System.out.println(number+" is not prime number"); }else{ for(i=2;i<=m;i++){ if(number%i==0){ System.out.println(number+" is not prime number"); flag=1; break; } } if(flag==0) { System.out.println(number+" is prime number"); } }//end of else } } |

11 is prime number

- Java program to calculate power of a number
- How to remove duplicate characters from String in Java?
- Fibonacci Series in Java Without Recursion
- Iterate value through Java HashMap
- Java program to remove punctuation from a given string
- Java Program to Implement Fisher-Yates Algorithm for Array Shuffling
- Java Program to Implement Gauss Seidel Method
- Java Program to Implement Gauss Jordan Elimination
- A Simple Merge based O(n) solution to find median of two sorted arrays
- Java program to count islands in boolean 2D matrix

Article Tags: java prime number, Java prime number program, Java program, Java programs, Java programs with examples, Java programs with output, java tutorial, Java tutorials, java tutorials with examples, prime number program in java

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok