# 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.** Write a Java recursive method to calculate the factorial of a given positive integer.

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

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

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

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

**6.** Write a Java recursive method to reverse a given string.

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

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

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

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

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

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

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

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

**15.** 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.**

**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

**Weekly Trends and Language Statistics**- Weekly Trends and Language Statistics