Respuesta :
Your main problem was declaring int prod in the while loop. This caused prod to be reset back to 1 every time the while loop ran.
Debugging a program involves locating and fixing the errors in a program.
The syntax of the given program is correct; this means that, the program will run without a hitch; however, the program will not give the expected output
The errors in the program are as follows:
- Placing int prod = 1; and System.out.print(prod) in the while loop
- Incorrect while statement
The fix to these errors are:
- Placing int prod = 1; and System.out.print(prod) outside the while loop
- Correct the while statement
So, the correct program is as follows:
import java.util.Scanner;
public class U4_L1_5_Activity_Two{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
int prod = 1;
while(num > 0){
prod = prod*num;
num--;
}
System.out.print(prod);
}
}
The texts in italics represent the fixes
Read more about debugging at:
https://brainly.com/question/23527739