Ayuda necesito validar mi programa pero sigue saliendo error
Publicado por Sergio (1 intervención) el 19/11/2021 23:12:40
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
import java.util.Scanner;
public class Pila {
Scanner teclado = new Scanner(System.in);
int PilaN[] = new int[5];
int tope=-1;
public void Insertar(){
if (tope >=PilaN.length-1) {
mensaje("La pilla esta llena");
}else{
tope+=1;
mensaje("Ingrese el dato: ");
PilaN[tope]=teclado.nextInt();
}
}
public void mensaje (String cad){
System.out.println(cad);
}
public int Borrar(){
if (tope==-1){
mensaje("La pila está vacia");
}else{
mensaje("Se ha eliminado un elemento de la pila") ;
PilaN[tope]=0;
}
return tope--;
}
public void Listar(){
for (int tope=4;tope>=0;tope--){
mensaje("Datos de la pila: "+PilaN [tope]);
}
}
public void Menu(){
int op;
do{
try {
mensaje("=====MENU=====");
mensaje("1.- Insertar");
mensaje("2.- Borrar");
mensaje("3.- listar");
mensaje("4.- Salir");
mensaje("=============");
mensaje("Elije una opcion:");
op = teclado.nextInt();
switch(op){
case 1:
Insertar();
break;
case 2:
Borrar();
break;
case 3:
Listar();
break;
case 4: break;
default: mensaje("Esa opcion no es valida");
break;
}
} catch (Exception a) {
mensaje("Error. Ingrese un entero: " + a.getMessage());
}
}while (op!=4);
}
public static void main(String[] a) {
Pila p = new Pila();
p.Menu();
}
}
Valora esta pregunta


0