Wednesday 9 December 2015

Java Program to check weather a Entered String is palindrome or not

Here is a java program to check weather a Entered String is palindrome or not. In this program we will ask user to enter a string and will check if it is palindrome. 
palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.

Source Code: 


import java.io.*;
class Palindrome
{
public static void main(String args[])
{
String s;
System.out.print("Enter a String: ");
Console con=System.console();
s=con.readLine();
char arr[];
arr=s.toCharArray();
char arr2[]=new char[arr.length];
for(int i=arr.length-1,j=0;i>=0;i--,j++)
{
arr2[j]=arr[i];
}
String s2;
s2=String.copyValueOf(arr2);
if(s.equalsIgnoreCase(s2))
{
System.out.println("Entered String is pallindrome");
}
else
{
System.out.println("Entered String isn't pallindrome");
}
}
}

Output:



No comments:

Post a Comment