Twin Prime Numbers :
The difference between two prime numbers are 2 those Prime numbers called as Twin Prime Prime Numbers
package my.TwinPrime;
import java.util.Scanner;
public class TwinPrime {
public static int primechecker(int n) {
int f = 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
f = 1;
break;
}
}
return f;
}
// main method begins execution of this class
public static void main(String args[]) {
int num1, num2;
Scanner sc = new Scanner(System.in);
System.out.print("Enter first number: ");
// Waiting for the user input
num1 = sc.nextInt();
System.out.print("Enter second number: ");
// Waiting for the user input
num2 = sc.nextInt();
// if both are prime and difference between them is 2
if (primechecker(num1) == 0 && primechecker(num2) == 0 && Math.abs(num2 - num1) == 2) {
System.out.println("The numbers are twin prime numbers");
} else {
System.out.println("The numbers are not twin prime numbers");
}
}
}
OUTPUT:
INTERVIEW QUESTION FOR JAVA
Java program for EMPLOYEE DETAILS
Java program for MULTIPLE THREADS ACCESSING ONE METHOD
Java program for SINGLE THREADS ACCESSING ONE METHOD
Java program for Strin Reverse
java Program for Twin Prime numbers
JAVA PROGRAM FOR EQUILATERAL TRIANGLE
JAVA PROGRAM FOR RIGHT ANGLE TRIANGLE
JAVA PROGRAM FOR SORTING OF ARRAY MINIMUM TO MAXIMUM WITHOUT USING SORTING METHOD
Java Program for Sorting Of Array Maximum to Minimum WITHOUT USING SORTING METHOD
JAVA PROGRAM FOR TO PRINT PRIME NUMBERS
JAVA PROGRAM FOR FIZZBIZZ , FIZZ BIZZ TEST
JAVA PROGRAM FOR MIRROR IMAGE OF RIGHT ANGLETRIANGLE
Comments
Post a Comment