import java.io.*;
class theseries
{
static int limit;
static int arr[]=new int[150];
static int j;
static int c;
static int k;
theseries()
{
j=0;
k=0;
c=0;
limit=0;
for(int i=0;i<150;i++)
arr[i]=0;
}
static void readList()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(read);
System.out.println("Enter the limit");
limit=Integer.parseInt(br.readLine());
System.out.println("Enter the "+limit+" nos in the array");
for(j=0;j<limit;j++)
arr[j]=Integer.parseInt(br.readLine());
}
static int IsPrime(int num,int y)
{
if(y<num)
{
if(num%y==0)
c=1;
return(IsPrime(num,y+1));
}
return c;
}
void PrintPrime(int m)
{
if(m==0)
System.out.println("The "+(k+1)+"th no in the series is prime "+arr[k]);
c=0;
}
public static void main(String args[])throws IOException
{
theseries ob=new theseries();
ob.readList();
for(k=0;k<limit;k++)
ob.PrintPrime(ob.IsPrime(arr[k],2));
}
}
class theseries
{
static int limit;
static int arr[]=new int[150];
static int j;
static int c;
static int k;
theseries()
{
j=0;
k=0;
c=0;
limit=0;
for(int i=0;i<150;i++)
arr[i]=0;
}
static void readList()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(read);
System.out.println("Enter the limit");
limit=Integer.parseInt(br.readLine());
System.out.println("Enter the "+limit+" nos in the array");
for(j=0;j<limit;j++)
arr[j]=Integer.parseInt(br.readLine());
}
static int IsPrime(int num,int y)
{
if(y<num)
{
if(num%y==0)
c=1;
return(IsPrime(num,y+1));
}
return c;
}
void PrintPrime(int m)
{
if(m==0)
System.out.println("The "+(k+1)+"th no in the series is prime "+arr[k]);
c=0;
}
public static void main(String args[])throws IOException
{
theseries ob=new theseries();
ob.readList();
for(k=0;k<limit;k++)
ob.PrintPrime(ob.IsPrime(arr[k],2));
}
}
No comments:
Post a Comment