forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwinPrime.java
41 lines (41 loc) · 863 Bytes
/
TwinPrime.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
class TwinPrime
{
static int a,b;
public TwinPrime()
{
a=b=0;
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter two positive integers");
a=sc.nextInt();
b=sc.nextInt();
}
int isPrime(int n)
{
int c=0;
for(int i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
return c;
}
int twinCheck(int a,int b)
{
if(isPrime(a)==2 && isPrime(b)==2 && ((a-b)==2 || (b-a)==2))
return 1;
return 0;
}
public static void main()
{
TwinPrime ob=new TwinPrime();
ob.input();
if(ob.twinCheck(a,b)==1)
System.out.print("Twin prime");
else
System.out.print("Not twin prime");
}
}