Advertisement
robeeeert

palindromoColas

Feb 7th, 2024
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package com.mycompany.palindromo;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Stack;
  5.  
  6. /**
  7.  *
  8.  * @author ianto
  9.  */
  10. public class Palindromo {
  11.  
  12.     public static void main(String[] args) {
  13.         Stack <Character> pila = new Stack <>();
  14.         String cadena = "";
  15.         Scanner entrada = new Scanner(System.in);
  16.         System.out.println("Ingrese la palabra");
  17.         cadena = entrada.nextLine();
  18.        
  19.         for(int i = 0; i<cadena.length(); i++){
  20.             pila.push(cadena.charAt(i));
  21.         }
  22.         String cadenaInvertida = "";
  23.         while(!pila.empty()){
  24.             cadenaInvertida += pila.peek();
  25.             pila.pop();
  26.         }
  27.         if (cadena.equalsIgnoreCase(cadenaInvertida)){
  28.             System.out.println("la frase es palindromo...." + cadena);
  29.         }else{
  30.             System.out.println("La frase No es palindromo...." + cadena);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement