Computer Science, asked by sheezach75, 9 months ago

How we can print all twin prime numbers less then 100 in java??

Answers

Answered by rsahab613
2

Explanation:

import java.util.Scanner;

public class Exercise16 {

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;

}

}

Similar questions