Computer Science, asked by Anonymous, 9 months ago

program to check two numbers are twin prime or not

Answers

Answered by yashneilplayz2009
0

Answer:

Explanation:

import java.util.Scanner;

class BrunsConstant

{

static boolean isPrime(int n)

{

int c=0;

for(int i=1; i<=n; i++)

{

if(n%i==0)

c++;

}

if(c==2)

return true;

else

return false;

}

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

System.out.println("Enter a number");

int n = in.nextInt();

double b=0;

System.out.println("Twin Primes");

for(int i=1; i<=n-2; i++)

{

//condition for twin prime

if(isPrime(i)&&isPrime(i+2))

{

System.out.println(i + "\t" + (i+2));

b += (double)1/i + (double)1/(i+2);

}

}

System.out.println("Value of Brun's Constant upto " +n+ " is : " +b);

}

}

Similar questions