218
Palindrome Program in Java
Palindrome number in java: A palindrome number is a number that is same after reverse. For example 545, 151, 34543, 343, 171, 48984 are the palindrome numbers. It can also be a string like LOL, MADAM etc.
Palindrome number algorithm
- Get the number to check for palindrome
- Hold the number in temporary variable
- Reverse the number
- Compare the temporary number with reversed number
- If both numbers are same, print “palindrome number”
- Else print “not palindrome number”
Let's see the palindrome program in java. In this java program, we will get a number variable and check whether number is palindrome or not.
Output:
palindrome number
Palindrome Program in Java (Another way)
You can also use a method where number or string is not predefined. Here, user has to put the number or string as input to check if the number/string is palindrome.
Output:
Use image PalindromeExample
Next TopicJava Programs