Question

A palindrome is a word, phrase, number, or other sequence of characters which reads the same...

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise.

public class Recursion {

                public static void main(String[] args) {

                                Recursion r = new Recursion();

                                System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true

                }

                public Boolean isPalindrome(int num){

                                return false;

                }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class Recursion {
  public static void main(String[] args) {
    Recursion r = new Recursion();
    System.out.println("Is 12321 a palindrome? "+r.isPalindrome(12321)); //true
  }

  public Boolean isPalindrome(int num){
    return num == rev(num,0);
  }

  int rev(int n, int temp) {
    if (n == 0)
      return temp;

    temp = (temp * 10) + (n % 10);
    return rev(n / 10, temp);
  }
}

Is 12321 a palindrome? true

Add a comment
Know the answer?
Add Answer to:
A palindrome is a word, phrase, number, or other sequence of characters which reads the same...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • This is a java question A palindrome is a word or phrase that reads the same...

    This is a java question A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and punctuations, and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: warts n straw radar Able was I ere I saw Elba tacocat Write a program named Palindrome.java that will accept a file (file name) from the command argument list and decide whether each line in the file is...

  • JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as...

    JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same...

    C++ Programming Palindrome Detector: A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man,a plan, a canal, Panama Desserts, I stressed Kayak Write a book function that uses recursion to determine if a string argument is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program, which continues to...

  • Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....

    Problem 1. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Problem 2. Modify the program to determine whether a seven-digit number...

  • A palindrome is a sequence of characters that reads the same backward as forward. For example,...

    A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • palindrome is a string that reads the same both forward and backward. C++ For example, the...

    palindrome is a string that reads the same both forward and backward. C++ For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

  • Palindrome Detector A palindrome is any word, phase, or sentences that reads the same forward and...

    Palindrome Detector A palindrome is any word, phase, or sentences that reads the same forward and backward. Here are some well-know palindrome. Write a bool function that uses recursion to determine if a string arguments is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program

  • A palindrome is a sequence of characters that reads the same backwards as forward. For example,...

    A palindrome is a sequence of characters that reads the same backwards as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Create an application that accepts a five-digit integer and determines whether it's a palindrome. Assume the user will enter only five digits, and never enter 0 as the first digit. I need the answer in visual studios please.

  • IN JAVA. Implement a method, public static boolean isPalindrome(String) to determine whether the specified String is...

    IN JAVA. Implement a method, public static boolean isPalindrome(String) to determine whether the specified String is a palindrome or not. A palindrome is a phrase that reads the same forward​and backward; not including punctuation, spaces, or letter case. Some example palindromes include: Just the method please..

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT