Gubbas Digi Communications

Gubbas Digi Communications

Palindrome





palindrome


import java.util.Scanner;
class Palindrome
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string to find out whether it is palindrome or not");
String str=sc.next(),str1="";

 char[] c=str.toCharArray();
for(int i=c.length-1;i>=0;i--)
{
str1=str1+c[i];

}
if(str1.equals(str))
{
System.out.println("the given string is palindrome");
}
else
{
System.out.println("the given String is not a palindrome");
}
        System.out.println(str1);
str1="";
        for(int i=str.length()-1;i>=0;i--)
{
          str1=str1+str.charAt(i);
}
System.out.println(str1);
if(str1.equals(str))
{
System.out.println("the given string is palindrome");
}
else
{
System.out.println("the given String is not a palindrome");
}
}
}
Output:
 Enter the string to find out whether it is palindrome or not
madam
madam
the given string palindrome

No comments:

Post a Comment