Check Palindrome String

Write a program to check if a string is palindrome or not.

public class MyClass {
    public static void main(String args[]) {
        String str = "madam";
        char ch [] = str.toCharArray();
        boolean isCheck = true;
        for(int i=0;i<ch.length/2;i++){
            if(ch[i] !=ch[str.length()-1-i]){
                isCheck = false;
            
            }
        }
        if(isCheck){
            System.out.println("Palindrome");
        }
        else{
            System.out.println("not palindrome");
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *