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

Write a Javaa program (name it PalindromInteger), to check if an integer value i

ID: 671850 • Letter: W

Question

Write a Javaa program (name it PalindromInteger), to check if an integer value is a palindrome or not, using 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 palin-
drome 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.

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 PalindromInteger
{
   public static int reversal(int number)
   {
       int reverse = 0;
       int temp = number;
       while(temp>0)
       {
           reverse = reverse*10+temp%10;
           temp = temp/10;
       }
      
       return reverse;
   }
  
   public static boolean isPallindrome(int number)
   {
       if(number == reversal(number))
           return true;
       else
           return false;
   }
   public static void main (String[] args) throws java.lang.Exception
   {
       // your code goes here
       Scanner input = new Scanner(System.in);
       System.out.println("Input the number : ");
       int number = input.nextInt();
       if(isPallindrome(number))
           System.out.println("Number is a pallindrome " );
       else
           System.out.println("Number is not a pallindrome " );
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote