Results 1 to 4 of 4
Thread: Without using reverse method
- 12-07-2010, 04:16 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 22
- Rep Power
- 0
Without using reverse method
how can I reverse a word "beautiful" without using Reverse() method?
I need to know because I'm going to make it as a basis for VB and C. I'm going to make a comparison. It will be my report that's why I really need to understand it.
I checked on some sites but they are using Reverse() Method.
Thanks a lot.Heart is the only broken thing that still works.
- 12-07-2010, 04:49 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
iterate over the string from the end to the beginning and use the charAt method and add these characters to the end of a new empty string / or use a stringbuilder
- 12-07-2010, 05:06 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,397
- Blog Entries
- 7
- Rep Power
- 17
... or do it the recursive way:
- if a String contains at most one character the String is its own reverse, otherwise:
- append the first character of the String to the reverse of the rest of the Sitrng.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-08-2010, 06:18 PM #4
Member
- Join Date
- Dec 2010
- Posts
- 11
- Rep Power
- 0
Here's what you want, isn't it?
Java Code:String s = "some text"; StringBuilder sb = new StringBuilder(); for (int i = s.length() - 1; i >= 0; i--) { sb.append(s.charAt(i)); } System.out.println(sb.toString());I'm a teenage Thai Java programmer who studying in secondary school.
Practicing English in process ...
Similar Threads
-
Reverse a string?
By cysquatch in forum New To JavaReplies: 15Last Post: 03-23-2010, 02:31 AM -
Purse Class ArrayList using for each loop for reverse, transfer method
By CEgan in forum New To JavaReplies: 0Last Post: 12-11-2009, 10:26 PM -
Reverse a string not using the substring method
By kathyla18 in forum New To JavaReplies: 17Last Post: 04-08-2009, 04:08 AM -
how do i reverse this method for sorting?Again!
By PureAwesomeness in forum New To JavaReplies: 2Last Post: 03-09-2009, 12:51 AM -
[SOLVED] how do i reverse this method for sorting?
By PureAwesomeness in forum New To JavaReplies: 3Last Post: 03-08-2009, 09:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks