Ad Code

Take an integer number as ‘n’ form user and calculate the factorial of that number using Java.

Program-
import java.util.*;
public class Factorial {
 public static void main(String[] args){
 Scanner sc = new Scanner(System.in);
 System.out.println("Enter a number : ");
 int n =sc.nextInt();
 double fact =1;
 for(int i=1;i<=n;i++){
 fact*=i;
 }
 System.out.println("factorial = " +fact);
 }
}
Reactions

Post a Comment

0 Comments