Results 1 to 3 of 3
Thread: Recursion
- 04-08-2009, 09:18 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 16
- Rep Power
- 0
Recursion
Hi, i want to know how this recursion is executing
Can someone please step through its execution showing the recursive process and the state of the system as it changes.XML Code:class P5PartA { public static void main(String args[]) { String data = new String("01101101"); System.out.println("Conversion: " + conversion(data)); } public static double conversion(String data) { return conversion(data, 0); } public static double conversion(String data, int index) { double result; int bit = Integer.parseInt(data.substring(data.length() - 1)); bit = bit * 2; if (data.length() == 1) { return Math.pow(bit, index); } result = conversion(data.substring(0, data.length() - 1), index + 1); if (bit != 0) { result = result + Math.pow(bit, index); } return result; } }Last edited by kathyla18; 04-08-2009 at 09:21 PM.
- 04-09-2009, 12:10 AM #2
What is stopping you from doing it yourself?
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
- 04-09-2009, 02:26 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Take a piece of paper and write-down what each line of this code do. If you really stuck on something ask your question at the time. We'll help you to find the solution.
This is not a bulky code lol. Just have a try first and show your effort.
Similar Threads
-
Recursion
By jachandru in forum New To JavaReplies: 1Last Post: 01-24-2009, 12:52 PM -
Recursion
By Mika in forum New To JavaReplies: 5Last Post: 01-04-2009, 01:13 AM -
Recursion help
By rjg_2186 in forum New To JavaReplies: 1Last Post: 01-02-2009, 08:03 AM -
Please help with recursion
By pheonix in forum New To JavaReplies: 9Last Post: 12-27-2008, 11:41 AM -
Recursion
By Zosden in forum AlgorithmsReplies: 4Last Post: 05-05-2008, 05:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks