Consider the following Java main method definition that computes the factorial o
ID: 3758604 • Letter: C
Question
Consider the following Java main method definition that computes the factorial of the number entered by the user. Fill in the blanks.
public static void main(String [ ] args)
{
int acc;
int n;
Keyboard kbd;
kbd = (FILL IN THE BLANK HERE)
acc = (FILL IN THE BLANK HERE)
System.out.println("Enter a number to compute the factorial of that number");
n = kbd.readInt();
while (n > 0)
{
acc = acc * n;
n = n - 1;
}
System.out.println( acc );
}
Explanation / Answer
class fact
{
public static void main(String [ ] args)
{
int acc;
int n;
//kbd = (FILL IN THE BLANK HERE)
acc = 1;
System.out.println("Enter a number to compute the factorial of that number");
n = kbd.nextInt();
while (n > 0)
{
acc = acc * n;
n = n - 1;
}
System.out.println( acc );
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.