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 ;(

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.