SHOW:
|
|
- or go back to the newest paste.
1 | import java.util.Scanner; | |
2 | ||
3 | public class Punto03 { | |
4 | public static void main(String[] args) { | |
5 | SimpleLinkedList<Integer> Random = new SimpleLinkedList<>(); | |
6 | SimpleLinkedList<Integer> Multiplos = new SimpleLinkedList<>(); | |
7 | SimpleLinkedList<Integer> Divisores = new SimpleLinkedList<>(); | |
8 | SimpleLinkedList<Integer> Restantes = new SimpleLinkedList<>(); | |
9 | Scanner entrada = new Scanner(System.in); | |
10 | int opc =0,valor = 0,validar=0; | |
11 | while (opc!=3){ | |
12 | opc=Helper.validarNumero(entrada, "\n'Opcion' \n1-Iniciar. \n2-Mostrar. \n3-Salir."); | |
13 | switch(opc){ | |
14 | case 1: | |
15 | CargaInicial(entrada,Random); | |
16 | valor=ValorX(entrada); | |
17 | Separar(Random,Multiplos,Divisores,Restantes,valor); | |
18 | ++validar; | |
19 | break; | |
20 | case 2: | |
21 | if (validar!=0) { | |
22 | System.out.println("\nLista De Multiplos de "+valor+": "); | |
23 | Multiplos.Mostrar(); | |
24 | System.out.println("\nLista De Divisores de "+valor+": "); | |
25 | Divisores.Mostrar(); | |
26 | System.out.println("\nLista De numeros Restantes "+valor+": "); | |
27 | Restantes.Mostrar(); | |
28 | } | |
29 | else { | |
30 | System.out.println("!!! ERROR:La lista aun no se ha cargado. !!!"); | |
31 | } | |
32 | break; | |
33 | } | |
34 | ||
35 | } | |
36 | } | |
37 | ||
38 | ||
39 | public static void CargaInicial(Scanner entrada,SimpleLinkedList random) { | |
40 | int continuar=1; | |
41 | while(continuar!=2) { | |
42 | int numero=generarRandom("Generando valor random...",100); | |
43 | random.addFirst(numero); | |
44 | continuar = Helper.validarNumero(entrada,"¿Generar otro numero?\n1-Si\n2-No"); | |
45 | } | |
46 | } | |
47 | ||
48 | ||
49 | public static int generarRandom(String mensaje,int x) { | |
50 | System.out.println(mensaje); | |
51 | int numRandom = (int) (Math.random() * x); | |
52 | System.out.println("Valor generado: "+numRandom ); | |
53 | return numRandom; | |
54 | } | |
55 | ||
56 | ||
57 | public static int ValorX(Scanner entrada){ | |
58 | int x; | |
59 | boolean pos=true; | |
60 | do { | |
61 | x=Helper.validarNumero(entrada,"Ingrese un valor de X positivo: "); | |
62 | if (x>0) { | |
63 | pos=false; | |
64 | } | |
65 | } | |
66 | while (pos==true); | |
67 | return x; | |
68 | } | |
69 | ||
70 | public static void Separar(SimpleLinkedList Random,SimpleLinkedList Multiplos,SimpleLinkedList Divisores,SimpleLinkedList Restantes,int valor) { | |
71 | int comparar=0; | |
72 | do { | |
73 | comparar=(int) Random.removeFirst(); | |
74 | if(comparar<=valor) { | |
75 | if(comparar%valor==0) { | |
76 | Divisores.addInOrder(comparar); | |
77 | } | |
78 | } | |
79 | if(comparar%valor==0) { | |
80 | Multiplos.addInOrder(comparar); | |
81 | }else { | |
82 | Restantes.addInOrder(comparar); | |
83 | } | |
84 | } | |
85 | while(Random.size()!=0); | |
86 | ||
87 | } | |
88 | ||
89 | } | |
90 |