Try this:
private static final int findMaxRecursively(List<Integer> numbers, int index, int max) {
return index >= numbers.size()
? max
: findMaxRecursively(numbers, index + 1, Math.max(numbers.get(index), max));
}
public static final int findMaxRecursively(List<Integer> numbers) {
return findMaxRecursively(numbers, 0, Integer.MIN_VALUE);
}
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, -1, 2, -2, 3, -3);
System.out.printf("Max is %d in %s%n", findMaxRecursively(numbers), numbers);
}
Answer from user4910279 on Stack OverflowCodingBat
codingbat.com › java › Recursion-1
CodingBat Java Recursion-1
Recursion strategy: first test for one or two base cases that are so simple, the answer can be returned immediately. Otherwise, make a recursive a call for a smaller case (that is, a case which is a step towards the base case). Assume that the recursive call works correctly, and fix up what ...
What's the best way to practice recursion?
I am trying to learn recursion in java and I was wondering if I could find some resources and exercises to help me practice. More on reddit.com
java - Recursion exercise - Stack Overflow
I'm new to Java and doing an exercise on recursion. I found this site and I could really use help breaking this down and explaining how this problem would be solved. Does this require the array to be More on stackoverflow.com
Recursive Methods - Oracle Forums
Hi, I new to java and programming. I'm trying to make sure I have a good handle on how to write recursive methods. I'm looking for some simple problems that can be solved with a recursive method. I'... More on forums.oracle.com
Is recursion a Bad Practice in general? - Stack Overflow
I always thought things that make your code uneasy to follow while being avoidable are considered as Bad Practice. Recursion seems to be one of these things (not to mention the problems it can caus... More on stackoverflow.com
Videos
45:39
Java Programming - Practice Recursion Problems - YouTube
Tricky Practice Java Recursion Problem (Explanation And Walkthrough) ...
11:11
Recursion in Java Full Tutorial - How to Create Recursive Methods ...
07:37
Java Recursion Examples - YouTube
03:18
Practice Recursion Problem - YouTube
GeeksforGeeks
geeksforgeeks.org › dsa › recursion-practice-problems-solutions
Recursive Practice Problems with Solutions - GeeksforGeeks
July 19, 2025 - Mutual Recursion with example of Hofstadter Female and Male sequences · Check if a destination is reachable from source with two movements allowed · Minimum steps to reach a destination · Identify all Grand-Parent Nodes of each Node in a Map · C++ program to implement Collatz Conjecture · Practice Questions for Recursion | Set 1 ·
Reddit
reddit.com › r › learnjava › comments › lcc3l6 › whats_the_best_way_to_practice_recursion
What's the best way to practice recursion? : r/learnjava
February 4, 2021 - I am trying to learn recursion in java and I was wondering if I could find some resources and exercises to help me practice.
W3Schools
w3schools.com › java › java_recursion.asp
Java Recursion
Infinite recursion is when the method never stops calling itself. Every recursive method should have a halting condition, which is the condition where the method stops calling itself.
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Recursion › recursionbasics.html
12.1. Recursion — AP CSA Java Review - Obsolete
The AP CS A exam usually has about 4-6 recursion problems. You only need to know how to trace recursive methods (figure out what they return or print).
Top answer 1 of 2
1
Try this:
private static final int findMaxRecursively(List<Integer> numbers, int index, int max) {
return index >= numbers.size()
? max
: findMaxRecursively(numbers, index + 1, Math.max(numbers.get(index), max));
}
public static final int findMaxRecursively(List<Integer> numbers) {
return findMaxRecursively(numbers, 0, Integer.MIN_VALUE);
}
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, -1, 2, -2, 3, -3);
System.out.printf("Max is %d in %s%n", findMaxRecursively(numbers), numbers);
}
2 of 2
0
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class RecursionUtils extends Object {
public static final int findMaxRecursively(List<Integer> numbers) {
if (numbers.size() > 0) {// terminating condition... if there are no
// elements remaining in the list then
// return 0..
int num1 = numbers.remove(0); // remove the first element of the
// list, thus in the process we
// truncate the list by one element.
int num2 = findMaxRecursively(numbers); // find the max from the
// rest of the list..
return num1 > num2 ? num1 : num2;
} else
return 0;
}
public static void main(String[] args) {
List<Integer> numbers = new LinkedList<>();
numbers.addAll(Arrays
.asList(new Integer[] { -1, -2, -3, 0, 6, 5, 3, 2 }));
System.out.println("The entered list is :");
System.out.println(numbers);
System.out.println("\nThe max element is : "
+ findMaxRecursively(numbers));
}
}
Oracle
forums.oracle.com › ords › apexds › post › recursive-methods-4382
Recursive Methods - Oracle Forums
March 14, 2013 - Hi, I new to java and programming. I'm trying to make sure I have a good handle on how to write recursive methods. I'm looking for some simple problems that can be solved with a recursive method. I'...
CodeHS
codehs.com › practice › java › recursion
Java Practice Problems
Java Practice Problems · Reverse String · Binary Search · Greatest Common Divisor · Least Common Multiple · Recurring Letters · Sum · Sum of Array Using Recursion · Magic Mirror Word Reverser · Recursive Factorial Calculation Back · Still have questions?
Iowa State University
home.engineering.iastate.edu › alexs › classes › 2007_Fall_207 › lab_manual › chapter11_lab.pdf pdf
Chapter 11: Recursion 221 Chapter 11: Recursion Lab Exercises Topics
Printing a string backwards can be done iteratively or recursively. To do it recursively, think of the following specification: If s contains any characters (i.e., is not the empty string) ... File Backwards.java contains a program that prompts the user for a string, then calls method printBackwards to print the
CodingBat
codingbat.com › java › Recursion-2
CodingBat Java Recursion-2
CodingBat code practice · Recursion-2 chance · Harder recursion problems. Currently, these are all recursive backtracking problems with arrays. Java Example Solution Code · Java String Introduction (video) Java Substring v2 (video) Java String Equals and Loops ·
DigitalOcean
digitalocean.com › community › tutorials › java-programming-interview-questions
Top Java Coding Interview Questions (With Answers) | DigitalOcean
April 17, 2025 - Focus on common interview topics: Study multithreading, concurrency, and Java-specific topics like serialization and reflection. Prepare to answer behavioral questions: Be ready to discuss your past projects, design decisions, and problem-solving approaches. Practice whiteboarding: Practice explaining technical concepts and designing systems on a whiteboard.
Tutorjoes
tutorjoes.in › java_programming_tutorial › recursion_function_exercise_programs_in_java
Java : Recursion Function - Exercises and Solution
1. Write a Java program to calculate factorial of a number using recursion View Solution
Learncs
learncs.online › lessons › java › practicewithrecursion
Learn CS Online: Practice with Recursion
Our suggestion is to have toMap create the map and then call a private recursive helper method to populate it. If the tree passed to toMap is null you should throw an IllegalArgumentException. You will need to import cs125.trees.BinaryTree, as well as Map and a Map implementation (probably HashMap) from java.util. We've provided some code to get you started. For reference, cs125.trees.BinaryTree has the following public properties: ... Need more practice?
w3resource
w3resource.com › java-exercises
Java programming Exercises, Practice, Solution - w3resource
The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises. It is recommended to do these exercises by yourself first before checking ...