Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA A number is a palindrome if its reversal is the same as itself. Write a program that reads in a number and outputs whether
JAVA
A number is a palindrome if its reversal is the same as itself. Write a program that reads in a number and outputs whether or not the number is a palindrome. Your program should include methods with the following headers:
// Return the reversal of an integer. For example, reverse(456) returns 654 public static int reverse(int number) // Return true if number is a palindrome and false if number is not a palindrome public static boolean isPalindrome(int number)
Your program should invoke the above methods to determine if the number that was read in is a palindrome and then report the result. Example input:
45654
Example output for above input:
45654 is a palindrome
Example input:
456
Example output for above input:
456 is not a palindrome
1 import java.util.Scanner; 2 3 public class PalindromeInteger 4 public static void main(String[] args) // Read in a number // Call isPalindrome to determine if the number is a palindrome and output the appropriate message. 6 7 8 9 public static int reverse(int number) /* Use the modulus operator (number % 10) to pick off the rightmost digit and build a new number using that digit (multiply the previous value of the number you're building by 10 and add the digit that was picked off) You will need a second variable for the number you're building Return the reversed number that you built. 10 12 13 14 15 16 17 18 19 20 21 public static boolean ?sPalndrome(int number) { / Call the reverse method to get the reverse of number and return true when the number is equivalent to the reverse otherwise return false 23
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started