forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwinPrime.java
More file actions
Latest commit
41 lines (41 loc) · 863 Bytes
/
Copy pathTwinPrime.java
File metadata and controls
41 lines (41 loc) · 863 Bytes
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
importjava.util.*;
classTwinPrime
{
staticinta,b;
publicTwinPrime()
{
a=b=0;
}
voidinput()
{
Scannersc=newScanner(System.in);
System.out.println("Enter two positive integers");
a=sc.nextInt();
b=sc.nextInt();
}
intisPrime(intn)
{
intc=0;
for(inti=1;i<=n;i++)
{
if(n%i==0)
c++;
}
returnc;
}
inttwinCheck(inta,intb)
{
if(isPrime(a)==2 && isPrime(b)==2 && ((a-b)==2 || (b-a)==2))
return1;
return0;
}
publicstaticvoidmain()
{
TwinPrimeob=newTwinPrime();
ob.input();
if(ob.twinCheck(a,b)==1)
System.out.print("Twin prime");
else
System.out.print("Not twin prime");
}
}