- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursiveMethod.java
More file actions
Latest commit
33 lines (30 loc) · 710 Bytes
/
Copy pathRecursiveMethod.java
File metadata and controls
33 lines (30 loc) · 710 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
publicclassRecursiveMethod {
publicstaticvoidmain(String[] args) {
System.out.println(factorialLoop(10));
System.out.println(factorialRecursive(10));
loop(10);
}
staticintfactorialLoop(intvalue){
varres = 1;
for(varcounter = 1;counter <= value;counter++){
res *= counter;
}
returnres;
}
staticintfactorialRecursive(intvalue){
if(value == 1){
return1;
} else {
returnvalue * factorialRecursive(value - 1);
}
}
// StackOverFlow Recursive
staticvoidloop(intvalue){
if(value == 0){
System.out.println("Selesai");
} else {
System.out.println("Value: " + value);
loop(value - 1);
}
}
}