Advertisement
LEANDRONIEVA

Ejercicio4Tp0

Aug 30th, 2022
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1. package tp0nuevo;
  2.  
  3. import tp0.Helper;
  4.  
  5. public class Tp0ejercicio4 {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.        
  10.         System.out.println("Ejercicio 4 Tp 0");
  11.         System.out.println("Veamos si un número es compuesto");
  12.         if (esCompuesto(ingresarNumero())) {
  13.             System.out.println("Su número es compuesto");
  14.         }else {
  15.             System.out.println("Su número es primo");
  16.         }
  17.         System.out.println("Fin del programa");
  18.     }
  19.     @SuppressWarnings("static-access")
  20.     public static Integer ingresarNumero() {
  21.         Helper help = new Helper();
  22.        
  23.         int parametro = help.getPositiveInt("Ingrese un número entero positivo para continuar ");
  24.  
  25.         return parametro;
  26.     }
  27.     public static boolean esCompuesto(int a) {
  28.         int contador = 0;
  29.         int i = 2;
  30.         while(i<=(Math.sqrt(a))) {
  31.             if (a%i==0)contador++;
  32.             i++;
  33.         }
  34.         if (contador>0) return true;
  35.         return false;
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement