Oct 13, 2021

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");



Enter the number:
Given number is palindrome

No comments:

Post a Comment

If you have any doubts, please discuss here...