-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample3.java
51 lines (38 loc) · 928 Bytes
/
Sample3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Recursion;//FACTOR�AL METODUYLA FAKT�R�YEL HESAPLAMA:(recursion(�zyinelemeli metodlar))
public class Sample3 {
public static void main(String[] args) {
int total=factorial(5);
System.out.println(total);
System.out.println("merhaba");
}
public static int factorial(int n) {
if(n==0)
return 1;
else
return n*factorial(n-1); //RECURSION metodu=fonksiyon kendi i�inde s�rekli �a��r�l�r
}
}
//NOT:Fakt�riyel Hesaplamak i�in while ve for d�ng�s�yle yap�m�:
/*WH�LE ile yap�m�---------------
*
int i=5;
int sonuc=1;
while(i>0) {
sonuc*=i;
i--;
}
System.out.println(sonuc); */
/*FOR ile yap�m�-----------------
*
* public static void main(String[] args) {
int sonuc = deger(5);
System.out.println(sonuc);
}
public static int deger(int x) {
int sonuc = 1;
for (int i = 1; i <= 5; i++) {
sonuc *= i;
}
return sonuc;
}
} */