Computer Science, asked by bhaumikpapri20, 2 months ago

Please answer question no. 7 as soon as possible no spamming ​

Attachments:

Answers

Answered by BrainlyProgrammer
20

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

Attachments:
Answered by Oreki
2

\textsf{\large \textbf{Algorithm}}

  \text{\textemdash \:\: Accepting the numbers using the \textbf{Scanner} class.}\\\text{\textemdash \:\: Checking primality and absolute difference of the accepted numbers.}\\\text{\textemdash \:\:  Printing suitable messages according to results obtained after the tests.}

Attachments:
Similar questions