fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static int factorial(int number) {
  11. System.out.println("N: " + number);
  12. if(number <= 1) {
  13. return 1;
  14. }
  15. System.out.println("R: " + number * factorial(number-1));
  16. return number * factorial(number-1);
  17.  
  18. }
  19.  
  20. public static void main(String[] args) {
  21. System.out.println(factorial(4));
  22. }
  23. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
N: 4
N: 3
N: 2
N: 1
R: 2
N: 1
R: 6
N: 2
N: 1
R: 2
N: 1
R: 24
N: 3
N: 2
N: 1
R: 2
N: 1
R: 6
N: 2
N: 1
R: 2
N: 1
24