Palindrome Program in Java: Number is Palindrome or Not
Published December 23, 2020What is a Palindrome Number?
A palindromic number is actually just a number that remains exactly the same when its digits are reversed. Quite simply, it's reflectional symmetry around a perpendicular axis. The expression palindromic is based on a palindrome, which describes to some note whose text is more unchanged if its own characters have been now reversed.
Algorithm for String Palindrome Program in Java
-
Take input from a user and store it in any variable.
-
Now copy the same number and store it in the temporary variable.
-
Reverse the temporary variable.
-
Compare the value of the temporary variable with the original string or number.
-
If they both are the same then print that the number is a palindrome.
-
If not then print that the number is not a palindrome.
Program to check whether the String is Palindrome or Not
import java.util.Scanner; |
Output:
Enter a string:
NITIN
NITIN is a palindrome
Program to check whether the Input Number is Palindrome or Not
public class PalindromeNumber { |
Output
Original Number: 252
Last digit: 2
Digit 2 added in sum 0
Original Number: 25
Last digit: 5
Digit 2 added in sum 20
Original Number: 2
Last digit: 2
Digit 2 added in sum 250
Number is Palindrome
If you are a Java beginner developer you want to start to create Java project then here are the 15 Java Projects for Beginners
Tags: palindrome program in java, palindrome string program in java, string palindrome program in java, palindrome number program in java
Article Contributed By :
|
|
|
|
581 Views |