w3resource

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.

Click me to see the solution

2. Recursive Sum from 1 to N

Write a Java recursive method to calculate the sum of all numbers from 1 to n.

Click me to see the solution

3. Recursive Nth Fibonacci Number

Write a Java recursive method to calculate the nth Fibonacci number.

Click me to see the solution

4. Recursive String Palindrome Check

Write a Java recursive method to check if a given string is a palindrome.

Click me to see the solution

5. Recursive Exponentiation (Power)

Write a Java recursive method to calculate the exponentiation of a number (base) raised to a power (exponent).

Click me to see the solution

6. Recursive String Reversal

Write a Java recursive method to reverse a given string.

Click me to see the solution

7. Recursive GCD of Two Numbers

Write a Java recursive method to find the greatest common divisor (GCD) of two numbers.

Click me to see the solution

8. Recursive Element Count in Array

Write a Java recursive method to count the number of occurrences of a specific element in an array.

Click me to see the solution

9. Recursive Sum of Odd Numbers in Array

Write a Java recursive method to find the sum of all odd numbers in an array.

Click me to see the solution

10. Recursive String Length

Write a Java recursive method to find the length of a given string.

Click me to see the solution

11. Recursive String Permutations

Write a Java recursive method to generate all possible permutations of a given string.

Click me to see the solution

12. Recursive Maximum in Array

Write a Java recursive method to find the maximum element in an array.

Click me to see the solution

13. Recursive Product of Array Elements

Write a Java recursive method to calculate the product of all numbers in an array.

Click me to see the solution

14. Recursive Sum of Digits in Integer

Write a Java recursive method to find the sum of the digits of a given integer.

Click me to see the solution

15. Recursive Array Sorted Check

Write a Java recursive method to check if a given array is sorted in ascending order.

Click me to see the solution

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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/java-exercises/recursive/index.php