Concept

How is recursion implemented in Java?

ComputerScienceOne / Recursion

"Java supports recursion with no special syntax necessary. However, as an object-oriented language, recursion is generally expensive and iterative or other non-recursive solutions are generally preferred. We present a few examples to demonstrate how to write recursive methods in Java. The first example of a recursive method we gave was the toy count down example. In Java it could be implemented as follows.\n\n1 public static void countDown(int n) {\n\n2 if(n == 0) {\n\n3 System.out.println(\"Happy New Year!\");\n\n4 } else {\n\n5 System.out.println(n);\n\n6 countDown(n-1);\n\n7 }\n\n8 }"

Related Ideas

How is recursion implemented in Java? | ComputerScienceOne | Bifalgorithm | Bifalgorithm