Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. // Opgavebeskrivelse: Skriv en rekursiv metode (factorial(5)), som beregner factorial af n=5.
  2.  
  3. private static int factorial(int n) {
  4. if (n > 0) {
  5. if (n == 1) return 1;
  6. else {
  7. return n * factorial(n - 1);
  8. }
  9. } else return(0);
  10. }
  11.  
  12. public static void main(String[] args) {
  13. System.out.println("Result is " + factorial(5) + ".");
  14. }
Add Comment
Please, Sign In to add comment