by Dinesh Thakur Category: Control Structures

 

import java.io.*;

class PrimeNumber
{
            public static void main(String args[] )
            throws IOException
            {
                        BufferedReader Prime=new BufferedReader(new InputStreamReader(System.in));
                        String CPN;
                        int i,x,Number,m;
                        System.out.print("Check Number to Prime or Not : ");
                        CPN=Prime.readLine();
                        Number=Integer.parseInt(CPN);
                        x=0;
                        for(i=2;i<=Number-1;i++)
                        {
                                    m=Number%i;
                                    if(m==0)
                                    {
                                                System.out.println(Number +" Number is not Prime");
                                                x=1;
                                                break;
                                    }
                        }
                        if(x==0)
                        {
                                    System.out.println(Number +" Number is a Prime Number");
                        }
            }
}


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article