Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created September 20, 2019 17:13
Show Gist options
  • Save parzibyte/5d10916fd42019816d2fd110a0532c6d to your computer and use it in GitHub Desktop.
Save parzibyte/5d10916fd42019816d2fd110a0532c6d to your computer and use it in GitHub Desktop.
public static boolean esPrimo(int numero) {
// El 0, 1 y 4 no son primos
if (numero == 0 || numero == 1 || numero == 4) {
return false;
}
for (int x = 2; x < numero / 2; x++) {
// Si es divisible por cualquiera de estos números, no
// es primo
if (numero % x == 0)
return false;
}
// Si no se pudo dividir por ninguno de los de arriba, sí es primo
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment