Results 1 to 10 of 10
- 05-07-2011, 12:50 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 2
- Rep Power
- 0
-
You write code that does this for you. What have you tried so far?
- 05-07-2011, 01:24 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
And even before the code think about how you rather than the computer would get the output from the input. Does it involve splitting the original string up in some way? And doing something to the component parts?
The thing is, you have to be comprehensive and specific with your "recipe" - be able to describe the process you would use completely. This might involve being explicit about things that you are normally unconscious of: like "What is a number?"
- 05-07-2011, 02:24 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Cross posted How to reverse a string, skiping numbers , and ' ?
- 05-07-2011, 02:50 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
More consciousness raising: Be Forthright When Cross Posting To Other Sites at JavaRanch (applies generally, not just to that site)
- 05-07-2011, 04:12 PM #6
Suppose the sentence to be reserved is stored in str
Hope that your question is solved.Java Code:String temp; int length=str.length() - 1; char ch; for(int i=0;i<=length;i++) { ch=str.charAt(i); if (ch==" ") { reverse(temp); temp=""; System.out.print(" "); } else str=str.concat(ch); } void reverse(String s) { int length2=s.length()-1; for(int j=length2;j>=0; j++) { System.out.print(s.charAt(j)); } }All that a fellow passenger on this earth expects from you is your loving words and support. Never talk in a way that hurts others or insults them. Sarvejana Sukhinobavanthu.
- 05-07-2011, 04:17 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,412
- Blog Entries
- 7
- Rep Power
- 17
- 05-07-2011, 04:23 PM #8
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
And even if it doesn't compile, handing over solutions like that does next to nothing to help the original poster learn how to problem solve, debug, write code, and any other aspect that is essential to the learning process - all it does is help them cheat. Just this person's .02 thoughHope that your question is solved.
- 05-07-2011, 04:25 PM #9
Senior Member
- Join Date
- Mar 2011
- Posts
- 261
- Rep Power
- 3
The key to this, like others have said above, is getting the logic of how you would do this outside of programming, and then implementing that logic in your program by using the String class.
- 05-07-2011, 11:15 PM #10
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I agree entirely with this post. Do not spoonfeed! Ranjiths, please verify that your code is working before posting. If it is, don't post it! Give them a small nudge in the correct decision. Spoonfeeding more incorrect informastion will not help you.
Whenever you go to post something, stop for a second and think. Google if needed, do research and try to see if you can confirm what you thought before giving help.
@op: It may be helpful to create a method which reverses a single 1 word string. From there split should come in handy.
Similar Threads
-
help with returning the string in reverse
By thorobred in forum New To JavaReplies: 10Last Post: 04-24-2011, 12:21 AM -
How to reverse a string?
By Neeer in forum New To JavaReplies: 17Last Post: 03-27-2011, 08:10 PM -
Reverse A String Without Allocating A New String
By marco.c84 in forum Advanced JavaReplies: 10Last Post: 03-22-2011, 05:39 AM -
Reverse a string?
By cysquatch in forum New To JavaReplies: 15Last Post: 03-23-2010, 02:31 AM -
reverse a string with a while loop...
By OptimusPrime in forum New To JavaReplies: 9Last Post: 12-28-2009, 11:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks