Powered by Blogger.

Simple Java Program To Find Whether Number Is Prime or Not


/* Write a program to Find whether number is Prime or Not. */

class PrimeNumber{
      public static void main(String args[]){
          int number = Integer.parseInt(args[0]);
         int flag=0;          for(int i=2;i
         {
                    if(number%i==0)
              {
                 System.out.println(number+" is not a Prime Number");
                 flag = 1;
                 break;
              }
         }
         if(flag==0)
             System.out.println(number+" is a Prime Number");
    }
}

OTHER RESOURCES:

Check this program in my new website

C Program to find prime numbers in a given range

Share on Google Plus

About Unknown

Author is a Tech savvy and Web Enthusiast by nature and really love to help users by providing how-to posts and tech tutorials. He is a founder and author of technolamp.co.in and programming9.com. YouTube Channel to SUBSCRIBE:
    https://www.youtube.com/user/nvrajasekhar
Available: info@programming9.com
    Blogger Comment
    Facebook Comment

1 comments:

Unknown said...

Please give program for number a is prime number means just print if its not a prime number means just print before prime number.