Computer Science, asked by avi4817, 11 months ago


Twin primes are prime numbers whose difference is 2. For example: 3,5; 5, 7; 11, 13; 17, 19 etc
Write a program to print all twin-prime numbers from 2 to 200 (both inclusive).write a program in java language

Answers

Answered by bhuwanpaneru
0

Answer:

nter the search range: -1

End

I know that I am not complected the code, but I am struggling on how to print the Prime numbers in ( , ) ( , )way and how to calculate the number of twin primes show it at the end.

The below coding is what I had to do:

import java.util.Scanner;

import java.util.Random;

public class TwinPrimes {

public static void main(String[] args) {

int i = 0;

int A, B = 0, D = 0;

int num = 0;

System.out.println("Round" + " " + ++i + ":");

Scanner scn = new Scanner(System.in);

System.out.print("Enter the search range:");

A = scn.nextInt();

{

if (A < 0)

System.out.println("End");

}

for (i = 3; i <= A; i++) {

int counter = 0;

for (num = B; num >= 1; num--) {

{

if (B % num == 0) {

counter = counter + 1;

}

}

if (counter == 2) {

}

}

System.out.println("(" + i + "," + i + ")" + " " + "(" + i + "," + i + ")");

// sum Number of twin primes to

System.out.println("Number of twin primes less than or equal to " + A + " " + "is" + " ");

return;

}

}

}

Similar questions