Question

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..

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public static boolean isPalindrome(String s) {
    String modified = "";
    char ch;
    for(int i = 0; i < s.length(); ++i) {
        ch = s.charAt(i);
        if(Character.isAlphabetic(ch)) {
            modified += Character.toLowerCase(ch);
        }
    }
    int n = modified.length();
    for(int i = 0; i < (n/2); ++i) {
        if(modified.charAt(i) != modified.charAt(n-i-1)) {
            return false;
        }
    }
    return true;
}
Add a comment
Know the answer?
Add Answer to:
IN JAVA. Implement a method, public static boolean isPalindrome(String) to determine whether the specified String is...
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
  • Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is...

    Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is a palindrome, else false.


  • 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...

  • 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;...

  • Write a program that uses a recursive function to determine whether a string is a character-unit...

    Write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive comparisons and not ignoring spaces are indicated with flags. For example "A nut for a jar of tuna" is a palindrome if spaces are ignored and not otherwise. "Step on no pets" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive. Background Palindromes are character sequences...

  • Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome...

    Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome is a String that reads from right and left the same. An empty String, and a String with one character are Palindrome. public static boolean isPalindrome (String str) {

  • JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath...

    JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath, Mode mode) that will convert a file to Mocking Sponge Bob text in 3 different modes. EveryOther capitalize the first letter of the string capitalize every other letter (ignoring non-letter character like punctuation and spaces). non-letter characters don't count toward the every other count Example: mocking sponge bob! → MoCkInG sPoNgE bOb! Vowels capitalize every vowel (not including y) Random capitalize each letter with a probability of 35%....

  • in java Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue...

    in java Write a class named Palindrome.java and Write a method isPalindrome that takes an IntQueue as a parameter and that returns whether or not the numbers in the queue represent a palindrome (true if they do, false otherwise). A sequence of numbers is considered a palindrome if it is the same in reverse order. For example, suppose a Queue called q stores this sequence of values: front [3, 8, 17, 9, 17, 8, 3] back Then the following call:...

  • Implement the static method declared as follows: /** * Divides {@code n} by 2. * *...

    Implement the static method declared as follows: /** * Divides {@code n} by 2. * * @param n *            {@code NaturalNumber} to be divided * @updates n * @ensures 2 * n <= #n < 2 * (n + 1) */ private static void divideBy2(NaturalNumber n) {...} ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()() Implement the static method declared as follows: /** * Checks whether a {@code String} is a palindrome. * * @param s *            {@code String} to be checked * @return true if {@code...

  • 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...

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

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

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