Wednesday, 29 May 2013

Nested Prime

import java.io.*;
class Nestedprime
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,m,n,d,c,j;
        System.out.println("Enter the number to check the prime numbers upto the range u wish");
        n=Integer.parseInt(br.readLine());
        for(i=1;i<=n;i++)
        {
            c=0;
            for(j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c++;
                }
            }
       
            if(c==2)
            {
                System.out.println(i);
           }
        }  
    }
}

No comments:

Post a Comment