write a program in java whether a no is twin prime or not
Answers
Answered by
3
import java.util.*;
class TP
{
boolean isprime(int k)
{ int count=0;
for(int I=1;I<k/2;I++)
{
if (k%i==0)
count++;
}
if(count==1)
return true;
return false;
}
public static void main()
{
Scanner I=new Scanner(System.in);
System.out.println("Enter number up to which the twin prime are to be found");
int x=I.nextInt();
for(int I=1;I<x;I++)
{
for(int j=1;j<x;j++)
{
if((I-j)==2 && I.isprime()=true && j.isprime()==true)
System.out.println(I+" "+ j);
}
}
}
}
class TP
{
boolean isprime(int k)
{ int count=0;
for(int I=1;I<k/2;I++)
{
if (k%i==0)
count++;
}
if(count==1)
return true;
return false;
}
public static void main()
{
Scanner I=new Scanner(System.in);
System.out.println("Enter number up to which the twin prime are to be found");
int x=I.nextInt();
for(int I=1;I<x;I++)
{
for(int j=1;j<x;j++)
{
if((I-j)==2 && I.isprime()=true && j.isprime()==true)
System.out.println(I+" "+ j);
}
}
}
}
GeN21:
please correct minors errors if any
Similar questions