38) Write a program to input two integers
and check whether it’s Twins Prime or
not? (3,5 two Prime numbers which contain difference between two Primes is 2)
import java.util.*;
public class Tweens_prime
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter two numbers");
int a = sc.nextInt();
int b = sc.nextInt();
int co = 0;
int c = 0;
for(int i=1;i<=a;i++)
{
if(a%i==0)
c++;
}
for(int i=1;i<=b;i++)
{
if(b%i==0)
co++;
}
if(co==2&&c==2&&(a-b==2||a-b==-2))
{
System.out.println("Entered numbers are TWEENS PRIME ");
}
else
{
System.out.println("Entered numbers are not TWEENS PRIME ");
}
}
}