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

not geting desired output  RSS feed

 
shobhit pareek
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the output is somthing like thisisstupidand####idiotcomputer

but desired output is thisis####and####computer

please tell me wht could me the error then.
[ August 17, 2006: Message edited by: Gregg Bolinger ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you'll need to use equals() to compare two strings instead of ==. == is true if the two strings are the very same String object, while equals() is true for two String objects that happen to have the same value.

Second, I'm a little suspect of the logic. Think about a "found" flag to tell when you found the word in the "bad word" list.

See if those two fixes get you going. Post what you wind up with and we'll talk about some further improvements.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
First, you'll need to use equals() to compare two strings instead of ==. == is true if the two strings are the very same String object, while equals() is true for two String objects that happen to have the same value.


Although it will work in this case, because the array is populated with String literals.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first guess at why "stupid" was not caught was the == but you're right and maybe it's in the logic. I'm too sleepy to chase it further.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's definitely in the logic -- the inner "for" loop is useless. The "break" always occurs, which means that only "idiot" (the first bad word) is checked.

Henry
 
shobhit pareek
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WELL THANKS FOR ALL YOUR SUGGESTIONS BUT I HAVE FOUND A NEW LOGIC FOR THE PROBLEM.

THANKS ALL OF YOU AGAIN.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!