class palindrome
{
public static void main(String[] args)
{
StringBuffer s1=new StringBuffer(args[0]);
StringBuffer s2=new StringBuffer(s1);
s1.reverse();
System.out.println(“Given String is:”+s2);
System.out.println(“Reverse String is”+s1);
if(String.valueOf(s1).compareTo(String.valueOf(s2))==0)
System.out.println(“Palindrome”);
else
System.out.println(“Not Palindrome”);
}
}
Output:
Java palindrome madam
Given String is:madam
Reverse String is madam
Palindrome
Java palindrome harish
Given String is:harish
Reverse String is hsirah
Not Palindrome
Watevr Bullshits….nthng appropriate…jst a waste of tym….losrs!!!!!!!!
import java.util.Scanner;
public class PalindromeSentence
{
public static void main( String[] argv )
{
System.out.print( “Enter your phrase: ” );
String phrase = new Scanner(System.in).nextLine();
String eval = phrase.toLowerCase();
boolean isPalindrome = true;
int first , last;
for( first=0 , last=eval.length()-1 ; first < last ; first++ , last– )
{
while( (int)eval.charAt(first) ‘z’ ) first++;
while( (int)eval.charAt(last ) ‘z’ ) last–;
if( first > last || eval.charAt(first) != eval.charAt(last) ) isPalindrome = false;
}
System.out.printf( “\”%s\” is%s a palindrome.\n”, phrase, (isPalindrome ? “” : ” not” ) );
}
}
class palindrome
{
public static void main(String[] args)
{
String str = “malayalam”; // write a string name
StringBuffer sb = new StringBuffer(str).reverse();
String strRev = sb.toString();
if(str.equalsIgnoreCase(strRev))
{
System.out.println(” given string is Palindrome”);
}
else
{
System.out.println(” given string is Not a Palindrome”);
}
}
}
OUTPUT
GIVEN STRING IS PALINDROME
all sucking program nothing will compile
Im getting an error in StringBuffer example….
Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0
at Pallindrome.main(Pallindrome.java:10)
nee amma pukula sulli
okkati complie kadhu
excelent
i have written the program but i am facing problem to run it
this is helpful .. thanks guys.. God bless !!
import java.lang.*;
import java.io.*;
class palindrome
{
public static void main(String[]args) throws IOException
{
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“enter the string”);
str=br.readLine();
StringBuffer sb=new StringBuffer(str);
String strRev=new String(sb.reverse());
if(str.equalsIgnoreCase (strRev))
{
System.out.println(“it is a palindrome”);
}
else
{
System.out.println(“it is not a palindrome”);
}
}
}
Simplest of all above—–>
public Palindrome(String first,String second)
{
this.f1=first;
this.f2=second;
int num1=f1.length();
int num2=f2.length();
char a=f1.charAt(0);
char b=f2.charAt(num2-1);
if (num1==num2)
{
for(int i=0;i=0;j–)
{char d=f2.charAt(j);
if(c==d)
{
if(i==num1-1)
{System.out.println(“Palindrome”);
}
}
}
}
}
else
{System.out.println(“Not Palindrome”);}
}
public Palindrome(String first,String second)
{
this.f1=first;
this.f2=second;
int num1=f1.length();
int num2=f2.length();
char a=f1.charAt(0);
char b=f2.charAt(num2-1);
if (num1==num2)
{
for(int i=0;i=0;j–)
{char d=f2.charAt(j);
if(c==d)
{
if(i==num1-1)
{System.out.println(“Palindrome”);
}
}
}
}
}
else
{System.out.println(“Not Palindrome”);}
}
class Palindrome
{
public void input(String s)
{
boolean result=false;
String reverse=””;
for(int i=s.length()-1;i>=0;i–)
{
char ans=s.charAt(i);
reverse=reverse+ans;
result=s.equals(reverse);
if(result==true)
System.out.println(s+”is palindrome”);
else
System.out.println(s+”is not palindrome”);
}
}
}
public class Conversion1 {
public static void main(String[] args)
{
int i;
String s2=””;
String s1 = new String(“coffoc”);
int len_str = s1.length();
for(i=len_str-1;i>=0;i–)
{
s2 = s2+s1.charAt(i);
}
System.out.println(“Hence reverse of the string is:”+s2);
if(String.valueOf(s1).compareTo(String.valueOf(s2))==0)
System.out.println(“Palindrome”);
else
System.out.println(“Not Palindrome”);
}
}
Nice guys,this is very useful to me
if the given String is not a palindrome? how will you change it into a palindrome?
Check this link > http://www.msccomputerscience.com/2014/05/java-program-to-check-whether-string-is.html
public class String2 {
public static void main(String[] args) {
java.util.Scanner scn=new java.util.Scanner(System.in);
System.out.println(“enter a name”);
String s4=scn.nextLine();
String s2=””;
int m=s4.length();
System.out.println(m);
for(int i=m-1;i>=0;i–)
{
s2=s2+s4.charAt(i);
}
System.out.println(“reverse string=”+s2);
boolean x=s4.equalsIgnoreCase(s2);
if (x==true)
{
System.out.println(“Palindrome”);
}
else
System.out.println(“its not a Palindrome”);
}
}
public class Palindrome {
public static void main(String[] args) {
StringBuffer string = new StringBuffer(“malayalam”);
if (string.substring(0).equals(string.reverse().toString()))
System.out.println(“String is palindrom”);
else
System.out.println(“String is NOT palindrom”);
}
}
public class Palindrome {
public static void main(String[] args) {
StringBuffer string = new StringBuffer(“malayalam”);
if (string.substring(0).equals(string.reverse().toString()))
System.out.println(“String is palindrom”);
else
System.out.println(“String is NOT palindrom”);
}
}
public class Palindrome {
public static void main(String[] args) {
StringBuffer string = new StringBuffer(“malayalam”);
if (string.substring(0).equals(string.reverse().toString()))
System.out.println(“String is palindrom”);
else
System.out.println(“String is NOT palindrom”);
}
}
Another Simple one without importing any API’s,
public class FindPalindromeOrNot {
public static void main(String[] ar) {
String inputString = “liril”;
boolean isPalindrome = true;
char[] inputStringArr = inputString.toCharArray();
int length = inputStringArr.length;
int temp = length;
for (int n = 0; n < length; n++) {
temp -= 1;
if (inputStringArr[n] != inputStringArr[temp]) {
isPalindrome = false;
}
}
System.out.println("Is Palindrome = " + isPalindrome);
}
}
how do I make a program to show if word, sentence or number is palindrome
check Simple and easy program to find palindrome here http://www.javaengineeringprograms.com/program-to-check-palindrome-in-java/
Simple program. One more way to check string or number palindrome is http://www.explain-java.com/write-a-java-program-to-check-a-numberstring-is-palindrome-or-not-with-output/