Please answer question no. 7 as soon as possible no spamming
Answers
Question:-
- WAP to accept two numbers and check whether it is a twin prime or not.
What is twin prime number?
>> A pair of prime numbers with a difference of 2, i.e. 11 and 13.
//This is done in JAVA.
//Program to check if the two numbers are twin prime number or not.
package Programmer;
import java.util.Scanner;
public class Twin{
public static void main (String ar []){
Scanner sc=new Scanner (System.in);
System.out.println("Enter 2 numbers");
int a=sc.nextInt();
int b=sc.nextInt();
int c=0,C1=0;
for(int I=1;I<=a;I++){
if(a%i==0)
c++; }
for(int i=1;i<=b;i++){
if(b%i==0)
C1++; }
int d=(a>b)?a-b:b-a;
if((C1==2)&&(c==2)&&d==2)
System.out.println("Twin Prime");
else
System.out.println("Not Twin Prime");
}
}
_____
Variable Description:-
- a&b:- to accept Number as Input
- c&C1 :- Counter variable to count no. of factors of variable 'a'.
- d:- to calculate difference between two numbers
_____
•Output attached