Sep 3, 2019 in JAVA
Q: recursion in java

1 Answer

0 votes
Sep 4, 2019
Recursion in Java

Recursion in java is a process in which a method calls itself continuously. A method in java that calls itself is called recursive method.

It makes the code compact but complex to understand.

Syntax:

returntype methodname(){  

//code to be executed  

methodname();//calling same method  

}  

Java Recursion Example 1: Infinite times

public class RecursionExample1 {  

static void p(){  

System.out.println("hello");  

p();  

}  

  

public static void main(String[] args) {  

p();  

}  

}  

Output:

hello

hello

...

java.lang.StackOverflowError
Click here to read more about JAVA
Click here to read more about Insurance

Related questions

0 votes
Jun 17, 2019 in JAVA
...