Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

using arrays to identify palindromes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74721
336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
     
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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

     
    Ranch Hand
    Posts: 4716
    9
    Scala Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic