
Ayuda con código (Arreglos)
Publicado por Emmanuel (1 intervención) el 13/01/2022 05:02:22
Buen día, estoy aprendiendo java y no puedo realizar este ejercicio, ojala alguien pueda apoyarme.
Saludos y gracias de antemano.
/* Crear dos arreglos de 5 datos con los datos ordenados de manera ascendente, luego copiarlos en un tercer arreglo que contenga los 10 datos de ambas tablas, al copiarlos deberán seguir
* en orden ascendente.
*/
Saludos y gracias de antemano.
/* Crear dos arreglos de 5 datos con los datos ordenados de manera ascendente, luego copiarlos en un tercer arreglo que contenga los 10 datos de ambas tablas, al copiarlos deberán seguir
* en orden ascendente.
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package arreglos;
import java.util.Scanner;
public class Ejercicio4_14 {
public static void main(String[] args) {
int tabA[], tabB[], tabC[];
Scanner sc = new Scanner(System.in);
//LLenando la primer tabla (tabA)
tabA = new int[5];
System.out.print("Tabla A\nIngresa el dato 1: ");
tabA[0] = sc.nextInt();
for(int i=1; i<5; i++) {
System.out.print("Ingresa el dato " + (i+1)+": " );
tabA[i] = sc.nextInt();
while(tabA[i-1]>tabA[i]) {
System.out.println("El dato ingresado es menor que el anterior, ingresa otro...");
tabA[i] = sc.nextInt();
}
}
//LLenando la tabla B tabB
tabB = new int[5];
System.out.print("Tabla B\nIngresa el dato 1: ");
tabB[0] = sc.nextInt();
for(int i=1; i<5; i++) {
System.out.print("Ingresa el dato " + (i+1)+": " );
tabB[i] = sc.nextInt();
while(tabB[i-1]>tabB[i]) {
System.out.println("El dato ingresado es menor que el anterior, ingresa otro...");
tabB[i] = sc.nextInt();
}
}
//LLenando Tabla C
tabC = new int[10];
for(int i=0; i<5;i++) {
tabC[i] = tabA[i];
}
for(int b=0; b<5; b++) {
int i=(5+b), j;
for(j=0; j<9 && i>0; j++) { //Este bucle compara todas las posiciones del nuevo arreglo (tabC) con la tabla B (tabB)
if(tabC[(i-1)] >= tabB[b]) {
tabC[(i-1)] = tabC[i];
i--;
}
else {}
}
tabC[i]=tabB[b];
}
for(int j=0;j<10;j++) {
System.out.print("|"+ tabC[j]);
}
}
}
Valora esta pregunta


0