Roke98

Ejercicio4-Tp4-Unju

Oct 25th, 2022
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package Practico3;
  2.  
  3.  
  4.  
  5. public class Ejercicio4 {
  6.  
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.         menu();
  10.     }
  11.    
  12.     public static void menu() {
  13.         int opcion, opcion2, num;
  14.        
  15.         do {
  16.             SimpleLinkedList<Integer> factor = new SimpleLinkedList<Integer>();
  17.             System.out.println("1 - Ingresar un numero(Entero Positivo)");
  18.             System.out.println("2 - Generar un numero");
  19.             opcion = Helper.getPositiveInt("eliga una opcion");
  20.            
  21.             switch(opcion) {
  22.             case 1:
  23.                 num = Helper.getPositiveInt("Ingrese un Valor(Entero Positivo)");
  24.                 factor = factorizacion(num, factor);
  25.                
  26.                 System.out.println("Los factores pirmos de " + num + "\n"+ factor.toString());
  27.                 break;
  28.             case 2:
  29.                 num = Helper.randomInt(100);
  30.                 factor = factorizacion(num, factor);
  31.                
  32.                 System.out.println("Los factores pirmos de " + num + "\n"+ factor.toString());
  33.                 break;
  34.             default:
  35.                 System.out.println("Opcion no valida");
  36.             }
  37.            
  38.             opcion2 = Helper.getPositiveInt("Desea ingresar otro numero??Si=1//No=2");
  39.         }while(opcion2 != 2);
  40.         System.out.println("Gracias :D");
  41.     }
  42.    
  43.     public static SimpleLinkedList<Integer> factorizacion(int num, SimpleLinkedList<Integer> factor) {
  44.         int divisor = 2;
  45.         while (num != 1) {
  46.             if(num % divisor == 0) {
  47.                 factor.addLast(divisor);
  48.                 num = num/divisor;
  49.             }else {
  50.                 divisor++;
  51.             }
  52.         }
  53.         return factor;
  54.     }
  55.    
  56.     public static void multiplicidad(SimpleLinkedList<Integer> factor) {
  57.        
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment