Question: convert the source codes written in C below to Java applying the concept of Encapsulation #include int factorial(int n) { int fact = 1; for

convert the source codes written in C below to Java applying the concept of Encapsulation

#include

int factorial(int n)

{

int fact = 1;

for (int i = 1; i <= n; ++i) {

fact *= i;

}

return fact;

}

int num1 = 8, num2 = 3;

int main()

{

printf("In C ");

printf("Factorial of %d is %d ", num1, factorial(num1));

printf("Factorial of %d is %d ", num2, factorial(num2));

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!