Java Write the methods with the following headers Return the reversal of an inte
ID: 3758713 • Letter: J
Question
Java
Write the methods with the following headers Return the reversal of an integer, i.e., reverse(456) returns 654 public static mt reverse(int number) Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome. Hint: you can find the reverse of a number by one of the following two techniques: . Convert your number into a string, then reverse the string?s characters in a for loop using string concatenation and charAt() method. . Use the and % operators with a divisor equal to 10 in order to extract the individual digits and then combine these digits in a reverse order mathematically or by string concatenation.Explanation / Answer
public static int reverse(int number){
int result = 0,digit;
while(number > 0){
digit = number % 10;
result = result*10 + digit;
number = number /10;
}
return result;
}
public static boolean isPalindrome(int number){
return number == reverse(number);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.