Showing posts with label prime number series. Show all posts
Showing posts with label prime number series. Show all posts

Thursday, 13 June 2013

print prime number in given series

import java.io.*;
class simple_print_prime_number_in_given_series
{
    public static void main(String args[])
    {
        int start,end,i,j,a=1;
        try
        {
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter the number from where you find the prime number");
            start=Integer.parseInt(cin.readLine());
            System.out.println("Enter the number up to you want to find prime number ");
            end=Integer.parseInt(cin.readLine());
            System.out.println("The prime numbers in between "+start+" and "+end+" are");

            for(i=start;i<=end;i++)
            {
                for(j=2;j<i;j++)
                {
                    if(i%j==0)
                    {
                        a=0;
                        break;
                    }
                    else
                    {
                        a=1;
                    }
                }

                if(a==1)
                {
                    System.out.println(i);
                }
            }
        }
        catch(Exception e)
        {
            System.out.println("wrong data");
        }
    }
}