Created
November 29, 2019 18:35
-
-
Save gitaficionado/9b3bcc6f51c8462ecce6eeade89cd93f to your computer and use it in GitHub Desktop.
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. See page 215 in the Liang text more informaiton.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
/** | |
*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 | |
*palindromepublic static boolean isPalindrome(int number) | |
*/ | |
public class PalindromeInteger_06_03 { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
//Write a statement that asks user for a positive integer | |
//Create an if/else statement indicating whether the variable isPalindrome is or is not a palindrome. | |
public static boolean isPalindrome(int number) { | |
return number == reverse(number); | |
} | |
public static int reverse(int number) | |
{ | |
int result = 0; | |
________________ (number != __) { | |
int ________________ = number % 10; | |
____________ = _____________ * 10 + remainder; | |
___________ = ____________ / 10; | |
} | |
return _________________; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment