Skip to content

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 on…

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 w…

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…

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.joe…