Advertisements
The factorial of a nonnegative integer n is written n! (pronounced â?? n factorialâ??) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1 (for n=0) for example, 5!=5.4.3.2.1, which is 120 a) Write an application that reads a nonegative integer from the user and computes and print its factorial. b) Write an application that computes the value of ex by using the formula ex = 1+(x/1!)+(x2/2!)+(x3/3!)+(x4/4!)+....
import java.util.*; class Factorial{ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter Number: "); int m=input.nextInt(); long num=m; for(int i=m;i>1;i--){ num=num*(i-1); } System.out.println(num); } }