Java Program to check Prime Number

Prime Number Java Programming:
Any number which is divisible by 1 or itself is known as Prime Number.
For example : 2,5,7 are prime numbers as they are not divisible by any of the numbers except 1 and themselves.

Java Program to check Prime Number

/* Program to Find whether number is Prime or Not by */

class PrimeNo{

      public static void main(String args[]){

          int num = Integer.parseInt(args[0]);

         int flag=0;

         for(int i=2;i<num;i++){



                 System.out.println(num+" is not a Prime Number");

                 flag = 1;





             System.out.println(num+" is a Prime Number");



Output of Java Program to check whether a number is Prime or not.


Post a Comment