Roke98

Ejercicio4-Tp0-UNJU

Aug 26th, 2022 (edited)
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. package Practico0;
  2.  
  3. import java.util.Scanner;
  4.  
  5. import Practico0.Helper;
  6.  
  7. public class Ejercicio4 {
  8.  
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.        
  12.         hacer();
  13.  
  14.     }
  15.    
  16.     public static void hacer(){
  17.         Scanner sn = new Scanner(System.in);
  18.         String opcion;
  19.         do {
  20.             int numero = ingresarValor();
  21.             esCompuesto(numero);
  22.             System.out.println("Desea ingresar otro valor(s/n)");
  23.             opcion = sn.next();
  24.         }while(!opcion.equals("n"));
  25.         System.out.println("Gracais :D");
  26.     }
  27.    
  28.        
  29.     static void esCompuesto(int numero){
  30.         int contador = 0;
  31.         for(int I = 1; I <= numero; I++){
  32.             if((numero % I) == 0){
  33.                 contador++;
  34.             }
  35.         }
  36.         if(contador <= 2){
  37.             System.out.println(numero + " Es un numero primo");
  38.         }else{
  39.             System.out.println(numero + " Es un numero compuesto");
  40.         }
  41.     }
  42.    
  43.            
  44.     public static Integer ingresarValor() {
  45.         Helper help = new Helper();
  46.        
  47.         @SuppressWarnings("static-access")
  48.         Integer num = help.getInteger("Ingrese un numero positivo ");
  49.        
  50.         return num;
  51.     }
  52.    
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment