Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mycompany.palindromo;
- import java.util.Scanner;
- import java.util.Stack;
- /**
- *
- * @author ianto
- */
- public class Palindromo {
- public static void main(String[] args) {
- Stack <Character> pila = new Stack <>();
- String cadena = "";
- Scanner entrada = new Scanner(System.in);
- System.out.println("Ingrese la palabra");
- cadena = entrada.nextLine();
- for(int i = 0; i<cadena.length(); i++){
- pila.push(cadena.charAt(i));
- }
- String cadenaInvertida = "";
- while(!pila.empty()){
- cadenaInvertida += pila.peek();
- pila.pop();
- }
- if (cadena.equalsIgnoreCase(cadenaInvertida)){
- System.out.println("la frase es palindromo...." + cadena);
- }else{
- System.out.println("La frase No es palindromo...." + cadena);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement