Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 4 months ago. Improve this question So the goal of this code is to recursively move through a 2d
Tag: recursion
Print all cominations of numbers in ascending order recursively (with length n between 1 and 9)
I want to print all number combinations that are in ascending order. The output should go like: 012, 013, 014, …, 789 for n = 3. I tried to solve it using recursion, however I’m having the StackOverflowError. So it means it never reaches the result. Here is my code so far: Answer There are these issues in your code:
Count the Characters in a String Recursively & treat “eu” as a Single Character
I am new to Java, and I’m trying to figure out how to count Characters in the given string and threat a combination of two characters “eu” as a single character, and still count all other characters as one character. And I want to do that using recursion. Consider the following example. Input: Desired output: Current output: I’ve been trying
Adding two linked list ends in Infinite Loop
I’m trying to solve LeetCode problem 2. Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading
printing all subsequences of an array using recursion in JAVA
The following code for above requirement. However I am not getting proper output. There is problem with input list that I am passing in recursion Answer The problem is not, like you said in your comment, that the list ip keeps elements of the previous function call. The problem is that you don’t create a new arraylist as ip parameter
reverse a string using recursion with java
I am trying to write a recursion to reverse a String.This is my approach. I dont get why when it reaches the base case, where my a is already empty but I am still able to print out the reversed string. Answer you are not implementing any recursion, you just replaced two halves of a string.
How does parameters of a method get stored in stack during a recursive call?
I was doing a leetcode question https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ and I am confused on how parameters for a method get stored during a recursive call. If a node gets visited, I wanted to save it’s state that it was visited. When I send two variables, when the stack is getting unwinded the updated variable values are being lost. But if I send
How to tidying my Java code because it has too many looping [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 10 months ago. Improve this question I have a Node class used to represent a tree structure. Within this class, I’ve defined a print method that
I want to swap characters of string in java but it returns garbage value can you please tell me what is wrong with my code
I want to swap characters of string but this program returns garbage value. Can you please tell me what is wrong with my code. Answer You have to use constructor of String class. Then it will work fine.
How do I approach this recursively in Java?
In this program I need to get input from the user that indicates the length of the numbers with this quality: The number should be prime and if you delete each digit from the right the number that is left should still be prime. i.e. 2399 is such a number. Because 2399 is prime, and also 239, and 23, and