please help :( Q3. Write the methods with the following headers // Return the re
ID: 3760472 • Letter: P
Question
please help :(
Q3. Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) returns 654 public static int reverse(int number) // Return true if number is a palindrome public static boolean isPalindrome(int number) Use the reverse method to implement is Palindrome. A number is a palindrome if its reversal s the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome. (10 marks) 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 concatenation. Sample runsExplanation / Answer
class Palindrome{
public static int reverseNumber(int n){
int temp,rnum= 0;
while(n > 0){
rnum = rnum*10 + n%10;
n = n/ 10;
}
return rnum;
}
public static Boolean isPalindrome(int n){
return n == reverseNumber(n);
}
public static void main(String args[]){
System.out.println(isPalindrome(4554));
System.out.println(isPalindrome(123));
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.