PROBLEM 1 : FACTORIAL OF A NUMBER
In mathematics, the factorial of a
non-negative integer n
denoted by n!,
is the product of all positive integers less than or equal to n.
For example:
6! = 6 x 5 x 4 x 3 x 2 x 1 = 720
Input
The first line of the input contains
an integer N (1 ≤N ≤ 5), the number of test cases. Following the
first line are the test cases. Each line in a test case contains a
non-negative integer number.
The
input must be read from standard input.
Output
The
output of the program should print the result of the factorial of
the numbers.
The
output must be written to standard output.
Sample
Input
|
Sample
Output
|
3
6
7
8
|
720
5040
40320
|
Solution :
import java.util.*;
public class factorial {
public static void main(String [] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
for(int x=0;x<num;x++) {
int total=1;
int no = scan.nextInt();
for(int y=1;y<=no;y++)
total = total*y;
System.out.print(total + "\n");
}
}
}