aspose file tools*
The moose likes Beginning Java and the fly likes Need helps to solve the String manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need helps to solve the String manipulation" Watch "Need helps to solve the String manipulation" New topic
Author

Need helps to solve the String manipulation

Khong Biet Gi
Greenhorn

Joined: Apr 22, 2005
Posts: 1
i need to write an method that return the maximum number of consecutive blanks in the String parameter str1.

E.x: We have String: the method should return 3.

I take some time to try to solve the problem but ....no results.

Could you kindly give me some recomendations?

Thanks a lot

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Hi,Change this line to


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Once you make that change, you'll notice that your logic is not quite correct. As a suggestion without simply telling you how to fix it, note that naming variables with "temp" is rarely informative. Since every variable can be changed (unless it's final), they're all pretty much temporary.

While scanning the String, at any point you have the maximum number of spaces found previously and the number of spaces found in the current run of spaces. Write down before coding what you should do when you find a space and when you find a non-space. Also, before you start scanning you know that the current maximum is zero, but what happens when you finish scanning?

Finally, you'll want to try multiple test Strings, taking extra care to come up with "corner cases": inputs that may trigger special cases in your logic. One obvious special case is a String with no spaces. Can you think of others?
 
 
subject: Need helps to solve the String manipulation