Untitled
unknown
plain_text
4 years ago
491 B
4
Indexable
public class Recursion {
public static void main(String[] args) {
int fact = fac(5);
System.out.print(fact);
}
/*
* fac#5
* 5*4*3*2*1
*/
public static int fac(int n) {
if (n == 0) { // base condition
return 1;
} else {
return n * fac(n - 1); // اذا ماحطيت لها بيس كوندشن او نقطة للتوقف راح يصير انفنتي
}
}
}
// output = 120
Editor is loading...