Advertisement
Marin126

Ejercicio1Recu

Dec 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. /*
  7. * To change this license header, choose License Headers in Project Properties.
  8. * To change this template file, choose Tools | Templates
  9. * and open the template in the editor.
  10. */
  11. /**
  12. *
  13. * @author anton
  14. */
  15. public class Ejercicio01 {
  16.  
  17. public static void main(String[] args) {
  18. Scanner sc = new Scanner(System.in);
  19. System.out.print("Inicio: ");
  20. int inicio = Integer.parseInt(sc.nextLine());
  21. System.out.print("Fin: ");
  22. int fin = Integer.parseInt(sc.nextLine());
  23.  
  24. for (int i = inicio; i < fin; i++) {
  25.  
  26.  
  27. boolean primo = esPrimo(i);
  28.  
  29. if (primo) {
  30. System.out.println( i + " si es primo ");
  31. }else{
  32. System.out.println(i + " no es primo ");
  33. }
  34.  
  35.  
  36.  
  37. }
  38.  
  39. }
  40.  
  41. public static boolean esPrimo(int num) {
  42. boolean resultado = true;
  43. for (int i = 2; i < num-1; i++) {
  44. if (num % i !=0) {
  45. resultado = true;
  46. }else{
  47. resultado = false;
  48. break;
  49.  
  50. }
  51.  
  52.  
  53.  
  54. }
  55.  
  56.  
  57.  
  58. return resultado;
  59. }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement