Solve It By Java
Sunday, 29 November 2015
Factorial in Java
public class FactorialDemo {
public static void main(String[] args) {
System.out.println(""+factorial(5));
}
public static int factorial(int x) {
int fact = 1;
for(int i = 2; i <= x; i++) {
fact *= i;
}
return fact;
}
}
Output :
120
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment