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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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;
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply