Saturday, August 9, 2014

JAVA PROGRAM TO DISPLAY PRIME NUMBER ON GIVEN RANGE.

import java.io.*;
public class Primerange
{
    int t,n,i,f,on;
    public void input(int a)
    {
        t=a;
    }
   
    public void find()
    {
      for(n=1;n<=t;n++)
      {
        for(i=2;i<=n-1;i++)
        {
           if(n%i==0)
           {
                break;
           }
        }
       
        if(n==i)
        {
            System.out.print(" "+n);
        }
       }
    }
           
    public static void main(String args[])throws IOException
    {
        InputStreamReader in=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(in);
        int n;
        System.out.println("enter loop terms :");
        n=Integer.parseInt(br.readLine());
        System.out.println("Given loop terms : "+n);
        Primerange obj=new Primerange();
        obj.input(n);
        obj.find();
    }
}

No comments:

Post a Comment

JAC Board Computer || IIT 2025 || Introductory Information Technology || Class 10 || Practical Examination 2025

Marks Division HOE 30 Marks IT Application Report File 20 Marks Viva - Voce 10 Marks 1) Write an HTML code to generate a web p...