in JAVA by
Q:
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
Click here to read more about JAVA
Click here to read more about Insurance

Related questions

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