Interview Question
Country: United States
{{
import java.util.Scanner;
public class FactorialNum {
public static void main(String[] args) {
long temp, temp1;
Scanner input = new Scanner(System.in);
System.out.println("Enter the integer yo want to have factorial: ");
temp = input.nextLong();
temp1 = thatFact(temp);
System.out.println(temp1);
}
public static long thatFact(long test) {
long temp = 1, i, k;
for (i = 0; i <= test; i++) {
temp = test * (test - 1);
for (k = (test - 1); k > 1; k--) {
temp = temp * (k - 1);
}
}
return temp;
}
}}
- yny.all March 09, 2016