Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created November 29, 2019 18:35
Show Gist options
  • Save gitaficionado/9b3bcc6f51c8462ecce6eeade89cd93f to your computer and use it in GitHub Desktop.
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.
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