Palindrome String

Java Programming

Java Programming Examples

import java.io.*;
import java.util.Scanner;

class palin {
	palin(String str) {
		int i, j = 0;

		/* Declaration of character array with the length of string */
		char value[] = new char[str.length()];
		for(i = str.length()-1; i >= 0; i--) {

			/* Convert string to character array */
			value[i] = str.charAt(j);
			j++;
		}

		/* Convert character array to string */
		String temp = new String(value);

		/* Compare two string */
		if(str.equals(temp))
			System.out.print("It's a Palindrome String!");
		else
			System.out.print("It's not a Palindrome String!");
	}
}

class palindrome {
	public static void main(String args[ ]) {
		Scanner r = new Scanner(System.in);
		System.out.println("Program for Checking Palindrome String");
		System.out.println("Enter your String:");
		palin ps = new palin(r.nextLine());
	}
}


          /****** Output ******/
          

Program for Checking Palindrome String


Enter your String:


abcd


It's not a Palindrome String!




---------------------------------




Program for Checking Palindrome String


Enter your String:


abcba


It's a Palindrome String!

Learn more about Palindrome string