Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Faktoriaal
- {
- static int fakt(int arv)
- {
- int tulemus = 0;
- if (arv == 1)
- {
- tulemus = 1;
- }
- else
- {
- //2! = 1 * 2 = 1! * 2
- tulemus = fakt(arv - 1) * arv;
- }
- return tulemus;
- }
- public static void main(String[] args)
- {
- for (int arv = 1; arv <= 5 ; arv++)
- {
- int faktoriaal = fakt(arv);
- System.out.println(arv + "! =" + faktoriaal);
- }
- }
- }
Add Comment
Please, Sign In to add comment