Pages

Ads 468x60px

Monday 17 December 2012

Prime



    1.WAJP that prompts the user for an integer and then prints out all the prime numbers up to that Integer.
                                                        download link for program
      Program:

class Prime
{
  public static void main(String args[])
  {
    System.out.println(1+",");
   
    int n=Integer.parseInt(args[0]);
   
    boolean flag=false;
   
    for(int i=2;i<=n;i++)
   
    {
      int fact=2;
     
      while(fact<=i/2)
     
      {
        if(i%fact==0)
         {
            flag=true;
           
            break;
         }
         fact++;
      }
    if(flag==false)
    
     System.out.println(i);  
    }
  }
}   

0 comments:

Post a Comment

 

Sample text

Sample Text

Sample Text