Java Programming Calculate factorial using recursive function

Let's see the code and think how it works together. :)

import java.util.Scanner;

public class Factorial {

 /**
  * YaSolution.org
  */
 
 static int factorial(int a){
  if(a==0)
   return 1;
  else
   return factorial(a-1)*a;
 }
 
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  int num;

  System.out.print("Input a number: ");
  Scanner mysc = new Scanner(System.in);
  num = mysc.nextInt();

  System.out.print("The factorial of the input number is: " + factorial(num));
 }

}

Another way to calculate factorial : click here