• Post Reply Bookmark Topic Watch Topic
  • New Topic

using arrays to identify palindromes  RSS feed

 
davo tigora
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a program that would allow a user to input a phrase (with letters and spaces) and let them know whether or not it's a palindrome.

Here's my progress thus far:


I am trying to start a new method isPalindrome that will be responsible for creating an array with no spaces and then comparing characters to test if the phrase is a palindrome. What I don't quite understand are the parameters for this method. I keep getting an error that says an identifier is expected. Can someone help?
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when posting any code
davo tigora wrote:


What I don't quite understand are the parameters for this method.


The way you are starting your method definition is incorrect. The method must have been written in this manner

Now you pass your String variable (i.e. the variable which has the actual contents from the user) in your case it is "phrase" to the method parameter "checkString" and then do
your operation on checkString. You can call the method in this manner


Note you can use any name in place of "checkString" i.e. you can even use "phrase" but to avoid any confusion i just changed the name.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have added code tags to your post, and you can see how much better it looks. Always use spaces, not tabs, for indenting.
You are going about this the wrong way. you should divide your work into smaller pieces, like this:
  • 1: Remove spaces from string
  • 2: Convert to consistent case
  • 3: Check whether palindrome
  • You can make those all methods of a utility class.
    You should work out with paper pencil and eraser (the latter is the most important piece of hardware) how you intend to do it. Write out a String like this on paper:
    davo tigora
    Get rid of the spaces
    Work out how you can tell whether it is or is not a palindrome.

    Now you can convert that to code easily.
     
    Winston Gutkowski
    Bartender
    Posts: 10575
    66
    Eclipse IDE Hibernate Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    davo tigora wrote:Here's my progress thus far:

    Hi davo. I split up your enormous line 8 because it was screwing up the windowing here.

    Winston

     
    Randall Twede
    Ranch Hand
    Posts: 4696
    8
    Java Scala
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    this has already been answered but to make it more clear, your parameter must consist of a type and name. in this case the type is String
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!