Palindrome Number In Java

Hey, hello, how are you doing…. come let us learn palindrome number in java.

Palindrome Number In Java

Palindrome number is a number where number remain the same when its numbers are reversed.

example: Palindrome Number In Java

Also Read¬†–¬†Armstrong Number In Java Program

import java.util.Scanner;

public class Palindrome_Number_In_Java {

public static void main(String[] args) {

System.out.println("Please enter a number to reverse: ");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
int x = number;

// Here number entered is reversed
int reverse = 0;
int y;

while(number > 0)
{
y = number % 10;
reverse = reverse * 10 + y;
number = number / 10;
}

if(reverse == x)
System.out.println(x + " is a Palindrome Number.");
else
System.out.println(x + " is not a Palindrome Number.");
}
}

Output:

Palindrome Number In Java

Now, let us understand how above example executes. First a number is received as an input and stored in temporary variable(int x). In the next step we will reverse the number and then compared with the reversed number. Finally both numbers are checked, if both numbers are same then it is “palindrome number” else “it is not a palindrome number”.

About the author

admin

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *