Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//java Write the methods with the following headers // Return the reversal of an

ID: 3760161 • Letter: #

Question

//java

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 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. Sample runs Enter a postive integer: 3456 3456 is not palindrome Enter a postive integer: 45654 45654 is palindrome

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Palindrome
{
   public static int reverse(int number)
   {
       int digit;
       int reverseNo = 0;
       while(number>0)
       {
           digit = number%10;
           reverseNo = reverseNo*10+digit;
           number = number/10;
       }
       return reverseNo;
   }
  
   public static boolean isPalindrome(int number)
   {
       boolean result;
       if(number == reverse(number))
           result = true;
       else
           result = false;
          
       return result;
   }
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       Scanner input = new Scanner(System.in);
       int number = input.nextInt();
       if(isPalindrome(number))
           System.out.println("It is palindrome");
       else
           System.out.println("It is not palindrome");
   }
}