TCS Logo

Asked in TCS and 8 others

Write a function that checks if a given string is a palindrome or not.

AnswerBot
2y

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

Komal Goswami
2y

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

}

}

Seethannagari Sandhya Rani
2y

palindrome number is a number that is same after reverse. For example 121, 34543, 343, 131, 48984 are the palindrome numbers.

Palindrome number algorithm
  • Get the number from user
  • 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 C. In this c program, we will get an input from the user and check whether number is palindrome or not.

ADVERTISEMENT
ADVERTISEMENT
 
  1. #include<stdio.h>  
  2. int main()    
  3. {    
  4. int n,r,sum=0,temp;    
  5. printf("enter the number=");    
  6. scanf("%d",&n);    
  7. temp=n;    
  8. while(n>0)    
  9. {    
  10. r=n%10;    
  11. sum=(sum*10)+r;    
  12. n=n/10;    
  13. }    
  14. if(temp==sum)    
  15. printf("palindrome number ");    
  16. else    
  17. printf("not palindrome");   
  18. return 0;  
  19. }   

Output:

enter the number=151
palindrome  number

enter the number=5621
not palindrome  number


 For Videos Join Our Youtube Channel: Join Now
Feedback
  • Send your Feedback to feedback@javatpoint.com
Help Others, Please Share   
Learn Latest Tutorials

Splunk

SPSS

Swagger

Transact-SQL

Tumblr

ReactJS

Regex

Reinforcement Learning

R Programming

RxJS

React Native

Python Design Patterns

Python Pillow

Python Turtle

Keras

Preparation

Aptitude

Reasoning

Verbal Ability

Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

AWS

Selenium

Cloud Computing

Hadoop

ReactJS

Data Science

Angular 7

Blockchain

Git

Machine Learning

DevOps

B.Tech / MCA

DBMS

Data Structures

DAA

Operating System

Computer Network

Compiler Design

Computer Organization

Discrete Mathematics

Ethical Hacking

Computer Graphics

Software Engineering

Web Technology

Cyber Security

Automata

C Programming

C++

Java

.Net

Python

Programs

Control System

Data Mining

Data Warehouse



 
 
 
laxmi yadav
2y

a="palidrom"

b=(a[-1::-1])

if a==b:

print("palidrome")

else:

print("not palidrome")

Select
Add answer anonymously...

Interview Questions from Popular Companies

Accenture Logo
3.7
 • 8.7k Interviews
Amazon Logo
4.0
 • 5.4k Interviews
HCLTech Logo
3.5
 • 4.1k Interviews
Infosys Logo
3.6
 • 7.9k Interviews
Cognizant Logo
3.7
 • 5.9k Interviews
Wipro Logo
3.7
 • 6.1k Interviews
Tech Mahindra Logo
3.5
 • 4.1k Interviews
Capgemini Logo
3.7
 • 5.1k Interviews
undefined Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits