return factorial(value - 1)*value;
, , factorial(value - 1) value. , :
return (factorial(value - 1)) * value;
, 4, :
factorial(3) * 4;
(factorial(2) * 3) * 4;
((factorial(1) * 2) * 3) * 4;
1 * 2 * 3 * 4;
, , , :
4. if, , 3. ( , , , , , , . "" .)
if, , 2.
- if, ,
1. - if 1.
- , (
1) (2), (2). - , (
2) (3), (6). - , (
6) (4), (24).
, , 1 * 2 * 3 * 4, , .
, , :
private static int factorial(int value){
if (value == 1){
return 1;
}
int recursiveResult = factorial(value - 1);
return recursiveResult * value;
}
, "" , , . , ( ), , . . , :
int stackOverflow() { return stackOverflow(); }
, , - . , ; , stackoverflow. , :
void possibleStackOverflow(int arg) { if (arg == 0) return; possibleStackOverflow(arg - 1); }
possibleStackOverflow(10), , , , possibleStackOverflow(-1) .
, callStackOverflow (Integer.MAX_VALUE) StackOverflowException