Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Calculador_numeros_primos {
- public static void main(String[] args) {
- // % es un operador que nos devuelve el resto de dicha división
- // 10 % 2 -> 0
- // 10 %3 --> 0.333
- Scanner sc = new Scanner(System.in);
- System.out.println("=============================");
- System.out.println("Introduzca un número");
- int numero = sc.nextInt();
- boolean esPrimo=true; // Esta variable sirve para mandar el mensaje correcto
- //por pantalla, dependiendo de si es true o false.
- for (int a=2; a<numero; a++){
- if (numero % a == 0){
- esPrimo=false;
- break;
- }
- }
- if (esPrimo){
- System.out.println("Es primo");
- } else{
- System.out.println("No es primo");
- }//fin if-else
- }
- }
Add Comment
Please, Sign In to add comment