import java.util.Scanner;
public class SonGemelos
{
public static void main(String args[])
{
Scanner teclado = new Scanner(System.in);
System.out.print("\nIngrese el primer entero: ");
long entero1 = teclado.nextLong();
System.out.print("\nIngrese el segundo entero: ");
long entero2 = teclado.nextLong();
if ( sonGemelos(entero1, entero2) ) {
System.out.println("Son gemelos");
} else {
System.out.println("No son gemelos");
}
}
public static boolean sonGemelos(long a, long b)
{
return esPrimo(a) && esPrimo(b) && Math.abs(a - b) == 2;
}
public static boolean esPrimo(long numero)
{
if ( numero <= 1 ) return false;
long max = (long) Math.sqrt(numero);
for ( long i = 2; i < max / 2; ++i )
if ( numero % i == 0 )
return false;
return true;
}
}
Comentarios sobre la versión: 1 (0)
No hay comentarios