Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Added: May 3, 2021 7:06 PM
Views: 0
Tags: recursion
  1.  
  2. public class Main {
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.  
  7.         var solve = faculty(5);
  8.         System.out.println(solve);
  9.     }
  10.  
  11.     public static long faculty(long n){
  12.         if(n<0){
  13.             throw new IllegalArgumentException("n muss >0 sein!");
  14.         } else if (n==0){
  15.             return 1;
  16.         }else{
  17.             return n*faculty(n-1);
  18.         }
  19.     }
  20. }
  21.