- Check whether a string is palindrome or not..
This program helps to find the given string is palindrome or not.
//Program code
import java.util.*;
class Stringdemo
{
public static void main(String args[])
{
System.out.println("check the any String is palindrome or not.");
System.out.println("please enter any string");
String name,duplicate="";
Scanner obj= new Scanner(System.in);
name=obj.nextLine();
int length;
length=name.length();
System.out.println("length of the string="+length);
for(int i=name.length()-1;i>=0;i--)
{
duplicate = duplicate+name.charAt(i);
}
if(name.equals(duplicate))//String function to compare the string
{
System.out.println("yeah! string is palindrome");
}
else
{
System.out.println("oops! string is not
class Stringdemo
{
public static void main(String args[])
{
System.out.println("check the any String is palindrome or not.");
System.out.println("please enter any string");
String name,duplicate="";
Scanner obj= new Scanner(System.in);
name=obj.nextLine();
int length;
length=name.length();
System.out.println("length of the string="+length);
for(int i=name.length()-1;i>=0;i--)
{
duplicate = duplicate+name.charAt(i);
}
if(name.equals(duplicate))//String function to compare the string
{
System.out.println("yeah! string is palindrome");
}
else
{
System.out.println("oops! string is not
palindrome");
OUTPUT:


No comments:
Post a Comment