Hi, I would like to know if someone can clarify how to call methods in java menus. My question is the following (attached program for the example):
public void imprimir() {
Nodo reco=raiz;
System.out.println("Listado de todos los elementos de la pila.");
while (reco!=null) {
System.out.print(reco.info+"-");
reco=reco.sig;
}
System.out.println();
}
public void vacia() {
if(raiz==null) {
System.out.println("La pila esta vacia");
}
else {
System.out.println("Todavia caben mas valores en la pila, sigue insertando");
}
}
public void cantidad(){
Nodo reco=raiz;
int contador=0;
if(reco!=null) {
contador++;
reco=reco.sig;
}
else {
System.out.println("Hay "+contador+" nodos.");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner entrada=new Scanner(System.in);
System.out.println("1-Insertar 2-Extraer 3-Imprimir");
int op;
System.out.println("Declara la opcion que desea tomar :");
op=entrada.nextInt();
do {
switch(op) {
case 1:int x;System.out.println("Declara el numero a insertar");x=entrada.nextInt();insertar(x);break;
case 2:extraer;break;
case 3:imprimir();break;
}
}while(op!=1||op!=2||op!=3);
}
}
My doubt is in the switch case, when creating the cases I do not understand because sometimes we have to put in parentheses variables and sometimes not, and in some cases I get an error when I put the variable that I think is like in this case. If someone can explain how it works I would appreciate it. Thanks in advance.