Email: Password:       Forgot Password 
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.

Check A Number is Prime Or Not

Viewed:  1896 
Posted On:  23/07/2013 12:23:16 
In this article i am going to show you how we can check the number given by user is prime or not......... 


Below is my code:

import java.util.Scanner;

class prime
    public static void main(String s[]){
    int a,b;
    System.out.println("enter no. to check prime");
    Scanner scan=new Scanner(;
   System.out.println("you entered "+a);
System.out.println("no. is not prime");


      Step 1:  After writing this in notepad save the file with the name followed by (.java) for eg: I saved it with

Step 2 : 
Open command prompt 

Step 3 : Write javac - Press Enter for compilation

Step 4 : Write java Prime for execution


Check A Number Is Prime or Not.png

Image 1.

By Umesh  On  20/10/2014 03:27:26
Hello Good Article You can increase performance check number upto num/2 .. then it will reduce time complexity by half time. for(b=2;b<=a/2;b++) { if(a%b==0) { System.out.println("no. is not prime"); break; } } Thanks Umesh Happy Coding
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us