Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Practico3;
- public class Ejercicio4 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- menu();
- }
- public static void menu() {
- int opcion, opcion2, num;
- do {
- SimpleLinkedList<Integer> factor = new SimpleLinkedList<Integer>();
- System.out.println("1 - Ingresar un numero(Entero Positivo)");
- System.out.println("2 - Generar un numero");
- opcion = Helper.getPositiveInt("eliga una opcion");
- switch(opcion) {
- case 1:
- num = Helper.getPositiveInt("Ingrese un Valor(Entero Positivo)");
- factor = factorizacion(num, factor);
- System.out.println("Los factores pirmos de " + num + "\n"+ factor.toString());
- break;
- case 2:
- num = Helper.randomInt(100);
- factor = factorizacion(num, factor);
- System.out.println("Los factores pirmos de " + num + "\n"+ factor.toString());
- break;
- default:
- System.out.println("Opcion no valida");
- }
- opcion2 = Helper.getPositiveInt("Desea ingresar otro numero??Si=1//No=2");
- }while(opcion2 != 2);
- System.out.println("Gracias :D");
- }
- public static SimpleLinkedList<Integer> factorizacion(int num, SimpleLinkedList<Integer> factor) {
- int divisor = 2;
- while (num != 1) {
- if(num % divisor == 0) {
- factor.addLast(divisor);
- num = num/divisor;
- }else {
- divisor++;
- }
- }
- return factor;
- }
- public static void multiplicidad(SimpleLinkedList<Integer> factor) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment