
Asked in TCS and 8 others
Write a function that checks if a given string is a palindrome or not.

A program to check if a given string is a palindrome or not.
Convert the string to lowercase to ignore case sensitivity.
Remove all non-alphanumeric characters from the string.
Reverse the string and com...read more
import java.util.*;
class PalindromeExample2
{
public static void main(String args[])
{
String original, reverse = ""; // Objects of String class
Scanner in = new Scanner(System.in);
System.out.println("Enter a string/number to check if it is a palindrome");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1; i >= 0; i-- )
reverse = reverse + original.charAt(i);
if (original.equals(reverse))
System.out.println("Entered string/number is a palindrome.");
else
System.out.println("Entered string/number isn't a palindrome.");
}
}
A palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers. Palindrome number algorithm
Let's see the palindrome program in C. In this c program, we will get an input from the user and check whether number is palindrome or not. ADVERTISEMENT
ADVERTISEMENT
Output: enter the number=151 palindrome number enter the number=5621 not palindrome number |
- Send your Feedback to feedback@javatpoint.com
a="palidrom"
b=(a[-1::-1])
if a==b:
print("palidrome")
else:
print("not palidrome")
Interview Questions from Popular Companies










Reviews
Interviews
Salaries
Users

