• Home
  • Recent Q&A
  • Java
  • Cloud
  • JavaScript
  • Python
  • SQL
  • PHP
  • HTML
  • C++
  • Data Science
  • DBMS
  • Devops
  • Hadoop
  • Machine Learning
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

Related questions

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