Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10. This program computes the factorial of a nonnegative integer. Complete the p

ID: 3601019 • Letter: 1

Question

10. This program computes the factorial of a nonnegative integer. Complete the program Write output. Point 4 public static void main(Stringll args) f int n, k, fact ;// you are not allowed to change variables name and data type Scanner keyboard = new Scanner (System.in); System.out.print("Enter the value of n:"); n= keyboard.nextInt(); I/ missing initialization // Suppose you enter n=5 while ( k.=n ) // not allowed to change t / missing body of the loop System.out.print("The factorial is: " + fact); 3 //output: The factorial is:

Explanation / Answer

import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
int n,k,fact;
Scanner keyboard=new Scanner(System.in);
System.out.print("Enter the vale of n: ");
n = keyboard.nextInt();
k = 0;
fact =1;
while(k!=n)
{
fact*=(k+1);
k++;
}
System.out.print(" The factorial is: "+fact);
}
}

-----------------------------------------------------------------------------

//output

Enter the vale of n: 6

The factorial is: 720