diff --git a/numeros_primos.java b/numeros_primos.java new file mode 100644 index 0000000..4b14259 --- /dev/null +++ b/numeros_primos.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class numeros_primos { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("Ingresa un número entero positivo: "); + int num = sc.nextInt(); + boolean esPrimo = true; + + if (num <= 1) { + esPrimo = false; + } else { + for (int i = 2; i <= Math.sqrt(num); i++) { + if (num % i == 0) { + esPrimo = false; + break; + } + } + } + + if (esPrimo) { + System.out.println(num + " es un número primo."); + } else { + System.out.println(num + " no es un número primo."); + } + sc.close(); + } +}