0 votes
in JAVA by
recursion in java

1 Answer

0 votes
by
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

Related questions

0 votes
asked Sep 3, 2019 in JAVA by Robin
+2 votes
asked Jun 17, 2019 in JAVA by reins.robin
...