Skip to content
Advertisement

Tag: recursion

How does the recursion of printNStars work?

I don’t understand the output of this recursion. Can someone please help me? (flowchart will definitely help me understand..) Output of the code above: Answer It works in the following way: which can be translated into: there is also an exit rule. If n is 1, don’t draw previous rows. Just print one star. The executions will be in the

Java – Read files in a directory to a HashMap – recursive

Here below am trying to read fileNames from a nested folder structure into a hashmap, Structure is like HashMap contains “Sub FolderName” as Key & “FileNames”(ArrayList) as value. I’m trying to make a recursive call & save things into HashMap, but missing something in that, things are not being saved into HashMap. Please help me find out where am going

Coding Bat Recursion exercise (java)

How can I solve this problem recursively instead of using the replace method? I’m trying to get better a recursive methods. Given a string, compute recursively (no loops) a new string where all the lowercase ‘x’ chars have been changed to ‘y’ chars. I cheated and solved it this way and tried to look at the source code for Java

Convert Decimal to Hex using Recursive method Java

I need to make a recursive method that converts a decimal into hexadecimal. I can’t use Integer.toHexString. EDIT:I tried this code but it doesn’t work properly Edit: Changed the default case and the if (n == 0) loop return statement and it works beautifully now. new code: Answer The problem is in your default clause: it should read: That will

Java – using recursion to create all substrings from a string

The following code in Java uses recursion to create all possible substrings from a string. I am wondering is there a better way of coding this? I want to use recursion. FAQ Q – Why do I want to do this using recursion? A – Because the CEO of StackOverflow says recursion is important http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html Answer The following turned out

Are recursive methods always better than iterative methods in Java? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

Advertisement