So for the day 9 of code we will get familiar with the recursion technique.You can read in depth about Recursion from here.

**Task **

Write a factorial function that takes a positive integer, as a parameter and prints the factorial, Using Recursion technique.

Note: If you fail to use recursion or fail to name your recursive function factorial or Factorial, you will get a score of .

**Sample Input**

1 |
3 |

**Sample Output**

1 |
6 |

Hope you have tried by yourself and than finally you have landed here for the solution 🙂

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); while(in.hasNext()) { long n = in.nextLong(); long abc=factorial(n); System.out.println(abc); } } public static long factorial(long n) { if(n==0 || n==1) { return 1; } else return n*factorial(n-1); } } |

Hope you like the post.More upcoming 🙂