Write a program in Java to generate all the twin primes in the range 1 to N, where the value of N is entered by the user.

A **twin prime** is a pair of prime numbers with a difference of 2.

For example: 3, 5.

Sample Input:

N = 50

Sample Output:

3, 5

5, 7

11, 13

17, 19

29, 31

41, 43

```
import java.io.*;
class TwinPrime{
public static void main(String args[])throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("N = ");
int n = Integer.parseInt(br.readLine());
for(int i = 1; i <= n - 2; i++){
if(isPrime(i) && isPrime(i + 2))
System.out.println(i + ", " + (i + 2));
}
}
public static boolean isPrime(int num){
int f = 0;
for(int i = 1; i <= num; i++){
if(num % i == 0)
f++;
}
return f == 2;
}
}
```