Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Java Program to check Given Number is Palindrome or not

EX: Write a Java Program to check given Number is palindrome or not. How to write a java program to check palindrome number.


  What is Palindrome Number?

A palindrome number is a number that is same after reverse. For example: 252, 676, 77577, 1234321 etc.


  Program to print Given number is palindrome or not:


import java.util.Scanner;

public class PalindromeNumber {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int temp,r,sum=0;

System.out.println("Enter the number: ");
int num = sc.nextInt();//Getting input
temp = num;

while(num>0) {
r = num%10;
sum = (sum*10)+r;
num/=10;//=>num = num/10;
}

if(sum==temp) {
System.out.println("Given number is palindrome");
}else {
System.out.println("Given number is not palindrome");
}
}

}

Output:

Enter the number:
 575
Given number is palindrome





This post first appeared on Learn Coding With Examples, Solutions & Interview Questions, please read the originial post: here

Share the post

Java Program to check Given Number is Palindrome or not

×

Subscribe to Learn Coding With Examples, Solutions & Interview Questions

Get updates delivered right to your inbox!

Thank you for your subscription

×