write a program in Java to check whether the number is twin prime number or not
do using scanner class
Answers
Answered by
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
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
Math,
5 months ago
English,
11 months ago
Math,
11 months ago
CBSE BOARD X,
1 year ago
Math,
1 year ago