Necesito ayuda con mi codigo
Publicado por Nacho (4 intervenciones) el 24/06/2019 04:28:01
El problema es el siguiente, en el caso 3 y 4 el ciclo for no recorre el array, por lo tanto si el paciente esta ingresado en la posicion 1 (contando desde el 0) el ciclo nunca llega a esa posicion, precisaria saber cual es mi error, desde ya muchas gracias.
Aqui el codigo:
Aqui el codigo:
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package pacientes;
import java.util.Scanner;
public class Pacientes {
public static void main(String[] args) {
String[] nombre = new String[100];
int[] edad = new int [100];
Scanner sc = new Scanner(System.in);
System.out.println("******** GESTION DE PACIENTES ********"); System.out.println();
System.out.println("1. INGRESAR NUEVO PACIENTE");
System.out.println("2. BUSCAR PACIENTE");
System.out.println("3. ELIMINAR PACIENTE");
System.out.println("4. MODIFICAR PACIENTE");
System.out.println("5. VER TODOS LOS PACIENTES");
System.out.println("6. SALIR"); System.out.println();
int opcion;
int x = 0;
int i;
boolean encontrado = false;
String espacio;
do {
System.out.print("ELIJA UNA OPCION: ");
opcion = sc.nextInt();
switch (opcion) {
case 1:
System.out.print("INGRESE EL NOMBRE DEL PACIENTE: "); System.out.println();
espacio = sc.nextLine();
nombre[x] = sc.nextLine();
System.out.print("INGRESE EDAD DEL PACIENTE: "); System.out.println();
edad[x] = sc.nextInt();
x++;
break;
case 2:
String ingreso;
System.out.print("INGRESE NOMBRE DEL PACIENTE: "); System.out.println();
espacio = sc.nextLine();
ingreso = sc.nextLine();
for (i = 0; i < nombre.length; i++) {
if (ingreso.equals(nombre[i])) {
System.out.println("EL PACIENTE INGRESADO ES CORRECTO");
System.out.println("EDAD DEL PACIENTE: " + edad[i] + " AÑOS.");
encontrado = true;
}
}
if (!encontrado) {
System.out.println("EL PACIENTE NO FUE INGRESADO");
}
break;
case 3:
String ingreso2;
System.out.print("INGRESE EL NOMBRE DEL PACIENTE A ELIMINAR: ");
espacio = sc.nextLine();
ingreso2 = sc.nextLine();
for (i = 0; i < nombre.length; i++) {
if (ingreso2.equals(nombre[i])) {
nombre[i] = null;
edad[i] = 0;
System.out.println("EL PACIENTE FUE ELIMINADO");
break;
}
else {
System.out.println("EL PACIENTE NO FUE ENCONTRADO");
break;
}
}
break;
case 4:
System.out.print("INGRESE NOMBRE COMPLETO DEL PACIENTE A MODIFICAR: ");
espacio = sc.nextLine();
String mod_nombre = sc.nextLine();
for (i = 0; i < nombre.length; i++) {
if (mod_nombre.equals(nombre[i])) {
System.out.println("INGRESE EL NUEVO NOMBRE DEL PACIENTE: ");
nombre[i] = sc.nextLine();
System.out.println("INGRESE NUEVA EDAD DEL PACIENTE: ");
edad[i] = sc.nextInt();
System.out.println("DATOS ACTUALIZADOS DEL PACIENTE");
System.out.println("NOMBRE: " + nombre[i] + " EDAD: " + edad[i]);
break;
}
else {
System.out.println("EL PACIENTE NO FUE ENCONTRADO");
break;
}
}
break;
case 5:
for (i = 0; i < nombre.length; i++) {
if(nombre[i]!= null) {
System.out.println("PACIENTE: " + nombre[i] + " EDAD: " + edad[i]);
}
}
break;
}
} while (opcion != 6);
if (opcion == 6) {
System.out.println("USTED SALIO DEL SISTEMA.");
}
}
}
Valora esta pregunta


0