Palindrome:

palindrome is nothing but while revering the word we get the same word as result.

example:

wow=wow

level=level

mom=mom

dad=dad

malayalam=malayalam

program:

class Palindrome{
public static void main(String[] args) {
        String s="sobhi";
        String rs="";
        int len=s.length()-1;
        while(len>=0){
            rs=rs+s.charAt(len);
              len=len-1;
        }
        if(s.equals(rs)){
             System.out.println("palindrome");
        }
        else{
             System.out.println("not a palindrome");
        }
    }

output:

sobhika@sobhika-HP-Laptop-15-db1xxx:~$ javac Palindrome.java
sobhika@sobhika-HP-Laptop-15-db1xxx:~$ java Palindrome
not a palindrome


Leave a comment

Design a site like this with WordPress.com
Get started