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. private static long fact1(int a) {
  11. if (a <= 1) return 1;
  12. return a * fact1(a - 1);
  13. }
  14.  
  15. private static long fact2(int a) {
  16. long result = 1;
  17. while (a > 1) {
  18. result *= a;
  19. a--;
  20. }
  21. return result;
  22. }
  23.  
  24. public static void main(String[] args) {
  25. System.out.println(fact1(5));
  26. System.out.println(fact2(5));
  27. }
  28. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
120
120