my dog learned polymorphism*
The moose likes Java in General and the fly likes Wondering if someone can help me out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Wondering if someone can help me out" Watch "Wondering if someone can help me out" New topic
Author

Wondering if someone can help me out

Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
Hello all,

I've starting to teach myself Java from a bunch of books a while back and I ran across a programming problem in one of them that I can't figure out, and I was hoping someone here could.

The problem goes like this:

I need to check if a string reads the same forwards as backwards. Such as if the string was the word "radar".

The user will put in a string of characters ending with a period. I need to check this string and see if it's the same forwards as backwards minus the period. Disregarding blanks and making sure its Not case sensitive. I can't even figure out how to start this one. So any help would be appreciated.

Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

This gets asked a lot. Have a search through the forums for "palindrome" - you'll find plenty of ideas.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
Thanks for the advice.

I forgot to mention in my first post that this is a "homework assignment" so no actual code please. I just need a kick start in the right direction if you please. After all I'll never learn this if I just get stuff handed to me.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Exactly the qualities we appreciate. I happen to know a place to look, I'll go have a peek and see if I can give you some handy pointers.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Nope, those threads were looking at palindromic numbers (apparently that's a word). My hint: have a look at String.equals() and the other methods in String that do all the work for you
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Everything you need is in the API. Here's a hint, though. Remember, you can't change a String; it's immutable. So, you need to be able to construct an object which represents a String and you can change it (i.e. reverse it). Hmmmm...


James Carman, President<br />Carman Consulting, Inc.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

there are many ways to approach this... James suggests possibly creating a new, reversed string...

or, you could use a couple pointers (not C-style pointers, but more abstract pointers) to scan the string, one from the front, one from the back, and see if, as they iterate along the string, they always match...


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
Well, I guess it could be a class assignment to Jason(if you are still in college)... It would be a great idea to think like a programmer in such algorithmic stuff such as palindrome, fabonanci and so and so... So, guys, don't just give a direct answer... Let him develope his logical skill in programming by himself...

My hints would be that, Jason, you can have a look at the java.lang.String class and go thru the methods available there... They are pretty useful in processing character by character of a string in details... Hope this helps...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
Reverse? I've never heard of it and I can't find it in any of my books. How do you go about using it? That would make things so much easier then what I'm trying to do. Is that in the Buffer that I've been hearing about? I only have one book that even mentions the buffer and it only give a paragraph on it. Some additional explation would be wonderful!
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
http://java.sun.com/j2se/1.5.0/docs/api/index.html

Right there is the most useful link in the world for doing java stuff. You should be able to find all the methods/fields etc for StringBuffer, String etc.

If your teacher hasn't told you about that site he should be shot.

-Tad
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by Tad Dicks:

If your teacher hasn't told you about that site he should be shot.


And boiled in oil!
Jason Batchelder
Ranch Hand

Joined: Jan 27, 2005
Posts: 37
I didn't want to go into the whole sob story bit but it seems like I may have to by reading some of the posts here.

As a matter of fact I am/was going to college and I am/was taking Java.

The reason I say was is because about two months ago I was driving to work when my mini-van was hit by a cement truck. I'm told that they really didn't expect me to live but I'm not going to go that easy.

Anyway I'm no longer able to go physically to the college. Some days I can barely move. Rather then drop the classes I was taking though I've decided to stick it out and complete the semester by teaching myself. I was prommised a tutor to help me but so far the college has not been able to locate one.

Rather then continue to wait for one and fall even further behind and possibly ruin my 4.0 GPA I decided to go out on my own and see if I couldn't find some other means of help. (My GPA's not going down that easy either.) That brings us to my being here.

I am hoping that I can use you guys/gals for a substitue tutor until the college can find me one. That is why I've been asking the questions that I have been. It's not that I want my work done for me, I don't, it's just that I really don't know and teaching yourself on a tight schedual is a real drag and I could use some help.

So any help you guys can give would be great.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wondering if someone can help me out