Posted by: Sourav | July 7, 2014

Prime numbers in Java


import java.util.*;
class prime{
    static void primenumber()
    {
        int remain,sp=0;
    for(int j=2;j<=10;j++)
    {
      for(int i=2;i<=(j/2);i++)
      {
         remain=j%i;
         if(remain==0)
         {
          sp=1;
          break;
        }
       
       
    }
    if(sp==1)
    {
    System.out.println(“The number “+j+” is not a prime number”);
    sp=0;
}
else
{
     System.out.println(“The number “+j+” is a prime number”);
}
}
}
   
    public static void main(String args[])
   
   
    {
       
    
        primenumber();
       
       
       
    }
   
   
   
}
   

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: