Guest User

Untitled

a guest
Jan 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Calculador_numeros_primos {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. // % es un operador que nos devuelve el resto de dicha división
  8. // 10 % 2 -> 0
  9. // 10 %3 --> 0.333
  10.  
  11. Scanner sc = new Scanner(System.in);
  12.  
  13. System.out.println("=============================");
  14. System.out.println("Introduzca un número");
  15. int numero = sc.nextInt();
  16.  
  17. boolean esPrimo=true; // Esta variable sirve para mandar el mensaje correcto
  18. //por pantalla, dependiendo de si es true o false.
  19.  
  20.  
  21. for (int a=2; a<numero; a++){
  22.  
  23. if (numero % a == 0){
  24.  
  25. esPrimo=false;
  26. break;
  27. }
  28.  
  29. }
  30.  
  31. if (esPrimo){
  32.  
  33. System.out.println("Es primo");
  34. } else{
  35. System.out.println("No es primo");
  36. }//fin if-else
  37. }
  38.  
  39. }
Add Comment
Please, Sign In to add comment