Using Stack Bundle Exercise with Java Search

Asked

Viewed 18 times

0

I need to make an option using the Search of the Java Stack package, where the search will search a value typed by the user and tell whether he is in the list or not, if he is, you need to show the value that is just below him in the stack. The way I’m doing is not working because the.get(Indice) stack will show the Dice in the order the stack was placed, not the Dice it was found in using the search

 case 6 :    if ( pilha.empty() ) {
                                System.out.println("\n==> Pilha Vazia");
                            }else
                            {
                                System.out.println("\nDigite um valor para buscar: ");
                                valor1 = teclado.next();
                                indice = pilha.search( valor1 );
                                if ( indice > 0 ) {
                                    for (int i = 0; i < 1; i++) {
                                        System.out.println("Valor: "+pilha.get(indice)); 
                                    }
                                }else {
                                    System.out.println("Este valor não está presente na pilha.");
                                    }  
                            }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.