Advertisement
robeeeert

palindromo

Jun 24th, 2023
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. public class Palindromo {
  2.  
  3.     public static void main(String[] args) {
  4.         Stack <Character> pila = new Stack <>();
  5.         String cadena = "";
  6.         Scanner entrada = new Scanner(System.in);
  7.         System.out.println("Ingrese la palabra");
  8.         cadena = entrada.nextLine();
  9.        
  10.         for(int i = 0; i<cadena.length(); i++){
  11.             pila.push(cadena.charAt(i));
  12.         }
  13.         String cadenaInvertida = "";
  14.         while(!pila.empty()){
  15.             cadenaInvertida += pila.peek();
  16.             pila.pop();
  17.         }
  18.         if (cadena.equalsIgnoreCase(cadenaInvertida)){
  19.             System.out.println("la frase es palindromo...." + cadena);
  20.         }else{
  21.             System.out.println("La frase No es palindromo...." + cadena);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement