Java Recursive Methods: Exercises, Practice, Solution
Java Recursive Exercises [15 exercises with solution]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
1. Recursive Factorial Calculation
Write a Java recursive method to calculate the factorial of a given positive integer.
2. Recursive Sum from 1 to N
Write a Java recursive method to calculate the sum of all numbers from 1 to n.
3. Recursive Nth Fibonacci Number
Write a Java recursive method to calculate the nth Fibonacci number.
4. Recursive String Palindrome Check
Write a Java recursive method to check if a given string is a palindrome.
5. Recursive Exponentiation (Power)
Write a Java recursive method to calculate the exponentiation of a number (base) raised to a power (exponent).
6. Recursive String Reversal
Write a Java recursive method to reverse a given string.
7. Recursive GCD of Two Numbers
Write a Java recursive method to find the greatest common divisor (GCD) of two numbers.
8. Recursive Element Count in Array
Write a Java recursive method to count the number of occurrences of a specific element in an array.
9. Recursive Sum of Odd Numbers in Array
Write a Java recursive method to find the sum of all odd numbers in an array.
10. Recursive String Length
Write a Java recursive method to find the length of a given string.
11. Recursive String Permutations
Write a Java recursive method to generate all possible permutations of a given string.
12. Recursive Maximum in Array
Write a Java recursive method to find the maximum element in an array.
13. Recursive Product of Array Elements
Write a Java recursive method to calculate the product of all numbers in an array.
14. Recursive Sum of Digits in Integer
Write a Java recursive method to find the sum of the digits of a given integer.
15. Recursive Array Sorted Check
Write a Java recursive method to check if a given array is sorted in ascending order.
More to Come !
* To run the code mouse over on Result panel and click on 'RERUN' button.*
Java Code Editor
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics