Q:

Java Program to find all twin prime numbers

0

Java Program to find all twin prime numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public class demo1 
{ 
 public static void main(String[] args) 
 {
  for (int a = 2; a < 100; a++) 
  {
   if (PrimeNumber(a) && PrimeNumber(a + 2)) 
   {
    System.out.printf("(%d, %d)\n", a, a + 2);
   }
  }
 }
 public static boolean PrimeNumber(long b) 
 {
  if (b < 2) return false;
  for (int a = 2; a <= b / 2; a++) 
  {
   if (b % a == 0) return false;
  }
   return true;
 }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now