Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Palindrome sentence  RSS feed

 
El Bel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use a stack + queue to determine whether a sentence is a palindrome (ignoring spaces and punctuation). However my code returns false for the sentence below. Any ideas why? Thanks!

 
Paul Clapham
Sheriff
Posts: 22503
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dunno. You get two Strings and you compare them, you think they should be the same but they aren't. So print them out and look at them to see why not.
 
El Bel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I dunno. You get two Strings and you compare them, you think they should be the same but they aren't. So print them out and look at them to see why not.


Thank you. I thought about printing the strings and realised I needed to pop the characters from the stack onto str and remove characters from queue onto qu.
 
Campbell Ritchie
Marshal
Posts: 55751
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use java.util.Stack ←link. It tells you in the documentation what to use instead. Hint: this.
Don't write if (somethingBoolean) return true; else return false; You can find out what to use instead here (beware: old website).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!