Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pickles {
- /*
- // 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.
- */
- public static void main(String[] args) {
- // I'm making up all the syntax from memory, so it may not be perfect.
- // You can do the job of user input with scanner and stuff.
- }
- public static int reverse(int number) {
- return Integer.parseInt(revStr(Integer.toString(number)));
- }
- public static boolean isPalindrome(int number) {
- return number == reverse(number);
- }
- private static String revStr(String input) {
- return New StringBuilder(input).reverse().toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement