Question: Consider the following Java code which reads a positive integer ( other than zero ) from user input and calculates the factorial of that number
Consider the following Java code which reads a positive integer other than zero from user input and calculates the factorial of that number the factorial of an integer is the product of all integers from till the given integer:
Scanner userinput new ScannerSystemin;
int x userinput.next;
int i ;
int factorial ;
for i ; i x; i
factorial factorial i;
printlnThe factorial of x is factorial ;
a The program is not printing the correct factorial, even for x Construct the backward slice at the point of the line of code that prints the factorial to locate the root cause for this and correct the code.
b Calculate the dynamic slice of the original code, given an input of x Which one the static or the dynamic slice is more helpful in locating the root cause and why?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
