-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTwin_prime.java
More file actions
51 lines (47 loc) · 972 Bytes
/
Twin_prime.java
File metadata and controls
51 lines (47 loc) · 972 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
42
43
44
45
46
47
48
49
50
51
import java.util.*;
class Twin_Prime
{
int a,b;
Twin_Prime(int x,int y)
{
a=x;
b=y;
}
int isPrime(int n,int x)
{
if(n==x)
{
return 1;
}
else
{
if(n%x==0 || n==1)
{
return 0;
}
else
{
return isPrime(n,++x);
}
}
}
void display()
{
int x=isPrime(a,2);
int y=isPrime(b,2);
if(x==1 && y==1 && Math.abs(x-y)==2)
System.out.println("Twin Prime Numbers");
else
System.out.println(" Not Twin Prime");
}
public static void main()
{
Scanner in=new Scanner(System.in);
int a,b;
System.out.println("Enter the numbers");
a=in.nextInt();
b=in.nextInt();
Twin_Prime gg=new Twin_Prime(a,b);
gg.display();
}
}