Palindrom in java

Satyapriyanayak
Posted by Satyapriyanayak under Others category on | Points: 40 | Views : 539
In this Code Snippetswe will know whether a given string is palindrom or not.
A palindrome is a word, phrase, number that can be read the same way in either direction.


import java.util.*;
public class palindrom
{
public static void main(String arg[])
{
System.out.println("Provide a string to test");
Scanner sc=new Scanner(System.in);
String str1=sc.next();
String str2="";
for(int i=str1.length()-1;i>=0;i--)
str2=str2+str1.charAt(i);

if(str1.equals(str2))
System.out.println("Palindrom");
else
System.out.println("Not a palindrom");
}
}

Compile:-

javac palindrom.java
java palindrom

Comments or Responses

Login to post response