0

i have this code for palindrome

import java.util.*;
public class CheckPalindrome{
    public static void main(String[]args){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter String: ");
    String st=input.next();
    String str[]=st.split("");
    String reversedSt="";
    for(int i=str.length-1;i>=0;i--){
        reversedSt+=str[i];
    }
    if(st.equalsIgnoreCase(reversedSt)){
    System.out.println("String is palindrome");
    }
    else{
        System.out.println("String is not palindrome");
    }
    }
}

i need the same programme using stacks? can any one hlp
pllllz ;(

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by JamesCherrill
0

If you push the letters on to a stack the first letter will be at the bottom of the stack and the last letter will be at the top. Now if you pop them off the stack you will get the last letter first, and the first letter will be last. In other words, you will have reversed the order of the letters. That gives you your reversed word. If it's the same as the original word then it's a palindrome.
Try writing some code to implement what I just described.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.