Answer to Question #309531 in Java | JSP | JSF for Kyle

Question #309531

Write a java program that inputs an integer and outputs if the number is a Palindrome.



1
Expert's answer
2022-03-11T02:26:16-0500
public void palindrome(int num){
    int reversedNumber = 0;
    int temp;

    // store the number to originalNumber
    int originalNumber = num;

    // get the reverse of originalNumber
    // store it in variable
    while (num != 0) {
        temp = num % 10;
        reversedNumber = reversedNumber * 10 + temp;
        num /= 10;
    }

    // check if reversedNumber and originalNumber are equal
    if (originalNumber == reversedNumber) {
        System.out.println(originalNumber + " is Palindrome.");
    }
    else {
        System.out.println(originalNumber + " is not Palindrome.");
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS