Question

Using the programming language Java or C++, Write a function that takes an integer as input....

Using the programming language Java or C++,
Write a function that takes an integer as input. Return true if this integer is a palindrome integer; false otherwise;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class PalindromeExample{  

public static void main(String args[]){  

  

  Scanner in = new Scanner(System.in);  

System.out.println("Enter a number to check if it is a palindrome");

int n=in.nextInt();

int result=checkpal(n);

if(result ==1)    

System.out.println("palindrome number ");    

else    

System.out.println("not palindrome");

}

public static int checkpal( int n)

{

int r,sum=0,temp;

//It is the number variable to be checked for palindrome    

temp=n;

    while(n>0)

{

r=n%10;  //getting remainder  

   sum=(sum*10)+r;    

n=n/10;    

  }     

if(temp==sum)    

return 1;   

else    

return 0;

}  

}  

Add a comment
Know the answer?
Add Answer to:
Using the programming language Java or C++, Write a function that takes an integer as input....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT