8:49 pm - Thursday October 18, 2018

Java Example Program for palindrome

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author:Candidjava.com
*@Description: To check a Given number is palindrome or not
*/

public class Palindrome {
	public static void main(String[] args) {
		int n = 525;
		int rev = 0;
		int temp;
		System.out.println(n);
		temp = n;
		while (temp != 0) // use while loop to check a given condition
		{
			rev = rev * 10;
			rev = rev + temp % 10;
			temp = temp / 10;
		}
		if (n == rev)
			System.out.println("The number is palindrome:" + n);//  display the number is plandrome
																	
		else
			System.out.println("The number is not palindrome:" + n);  //display the number isn't   palindrome
																	
	}
}
 

Output:

525

The number is Palindrome:525

Filed in: Sample Programs in java

Comments are closed.