06 September, 2012

Prints out all prime numbers upto that integer

Program that prints out all prime numbers upto that integer


import java.io.*;
import java.lang.*;
import java.util.*;
class Prime
{
  public static void main(String args[])
  {
    int i,j,n;
    int count=0;
    Scanner s=new Scanner(System.in);
    System.out.println("Enter Number : ");
    n=s.nextInt();
    for(i=1;i<=n;i++)
    {
      count=0;
      for(j=1;j<=i;j++)
      {
        if(i%j==0)
         count++;
      }
      if(count==2)
      System.out.println("\t"+i);
     }
   }
}


No comments:

Post a Comment

Thank You !