Computer Science, asked by Padhai420, 11 months ago

write a program in Java to check whether the number is twin prime number or not
do using scanner class​

Answers

Answered by banabbigouri
2

public static void main(String[] args) {

for (int i = 2; i < 100; i++) {

if (is_Prime(i) && is_Prime(i + 2)) {

System.out.printf("(%d, %d)\n", i, i + 2);

}

}

}

public static boolean is_Prime(long n) {

if (n < 2) return false;

for (int i = 2; i <= n / 2; i++) {

if (n % i == 0) return false;

}

return true;

}

}

PLEASE MARK IT THE BRAINLIEST ANSWER.

Answered by abhishekmishra737007
1

Answer:

What I can do is:

int num= ... //input.

if(num>2)

{

boolean prev=true,ahead=true;

int c=(int)Math. sqrt(num+2);

for(int x=2;x<=c;x++)

{

if((num-2)%x==0)

Similar questions