/* Factorial and recursive function calls * * Author: Carsten Butz * Date September 2002 */ import tio.*; class Factorial{ public static void main (String[] args){ long l = factorial(4); System.out.println(l); } // public static long factorial(int n){ // // if(n<=1) // return 1; // else // return n*factorial(n-1); // // } public static long factorial(int n){ long r; if(n<=1) { System.out.println("factorial(" + (n) + ") returns the value 1"); return 1; } else { System.out.println("factorial(" + n + ") calls factorial(" + (n-1) + ")"); r = factorial(n-1); System.out.println("factorial(" + (n) + ") returns the value " + (n*r)); return n*r; } } }