How would I identify words in string?

edited January 2018 in How To...

How would I identify words in string?

Tagged:

Answers

  • edited January 2018

    Well, you can write a function to check this. The function will return a boolean value - true for "Yes, that is a palindrome!" and false for "Nope, that is not a palindrome!". The function will take in a String as input.

    Next, check to see if the input string has a length of 0 or 1. If it does, well, that's a palindrome, right? So your function would return true.

    Then check to see it the first letter and the last letter are the same. If the input string is input.length long, how can you use charAt() to access the last letter? How about the first letter?

    If they are different (you're comping them, yes?), then you DON'T have a palindrome, right? So you can return false.

    Now you just need to check if the rest of the letters (all but the first and last letters, I mean), also form a palindrome. If they do, well, then you have a palindrome.

    ... Do you have a function that can determine if a String is a palindrome? Can you use substring() to get the rest of the letters?

  • edited January 2018

    Once you have a function that can take a String and determine if it is a palindrome, you will need a for loop to try it with each of your input Strings in turn. What will your program output for palindromes? How can you get the String in reverse if it isn't one?

  • edited January 2018

    Or... since you're going to need the input String reversed anyway, maybe you should work out what the reversed input looks like first. For palindromes, how would the reversed input compare to the input? Is there a function that can reverse a String?

  • edited January 2018 Answer ✓

    Why do you keep asking the simplest questions....?

    I can’t believe you can’t do this.

    There is a reference to do your own research! Look at string charAt for-loop....

    and show the code of your attempts and your thought process !

  • How lame to just ask the question instead of telling us what your thoughts were.... but tfguy does it for you....

Sign In or Register to comment.