Posted by: Sourav | December 12, 2013

Palindrome in Java


import java.util.*;

class Palindrome
{
public static void main(String args[])
{
String original, reverse=””;
Scanner in = new Scanner(System.in);

System.out.println(“Enter a string to check if it is a palindrome”);
original = in.nextLine();

int length = original.length();

for ( int i = length – 1 ; i >= 0 ; i– )
reverse = reverse + original.charAt(i);

if (original.equals(reverse))
System.out.println(“palindrome.”);
else
System.out.println(“not a palindrome.”);

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: