Page 1 of 1

What's the output of the following code segment? public static void main(String[] args) { factorial(4); } public sta

Posted: Thu May 05, 2022 1:34 pm
by answerhappygod
What's the output of the following code segment?

public static void main(String[] args) {
factorial(4);
}
public static int factorial(int n) {
if(n <= 1) {
System.out.println(n);
return 1;
} else {
int res = n * factorial(n - 1);
System.out.println(res);
return res;
}
}