-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursion.java
More file actions
38 lines (30 loc) · 950 Bytes
/
Copy pathRecursion.java
File metadata and controls
38 lines (30 loc) · 950 Bytes
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
package classesIntro;
/**
* Created by WERT on 13.01.2017.
*/
public class Recursion {
// примеры рекурсивных методов
// обратный отсчет
void countdown(int i) {
if (i < 0) return;
System.out.print(i-- + " ");
countdown(i);
}
// заполнение массива значениями
void arrayFill(int[] arrayI, int length) {
if (length == 0) return;
arrayI[--length] = length;
arrayFill(arrayI, length);
}
// вывод значений массива в обратном порядке
void arrayPrint(int[] arrayI, int length) {
if (length == 0) return;
System.out.print(arrayI[--length] + " ");
arrayPrint(arrayI, length);
}
// вычисление факториала от числа n
int fact(int n) {
if (n == 1) return 1;
return fact(n - 1) * n;
}
}