Guest User

Untitled

a guest
Jun 24th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Faktoriaal
  2. {
  3. static int fakt(int arv)
  4. {
  5. int tulemus = 0;
  6. if (arv == 1)
  7. {
  8. tulemus = 1;
  9. }
  10. else
  11. {
  12. //2! = 1 * 2 = 1! * 2
  13. tulemus = fakt(arv - 1) * arv;
  14. }
  15. return tulemus;
  16. }
  17. public static void main(String[] args)
  18. {
  19. for (int arv = 1; arv <= 5 ; arv++)
  20. {
  21. int faktoriaal = fakt(arv);
  22. System.out.println(arv + "! =" + faktoriaal);
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment