Problem:
Write a java method returns the factorial of a number using iteration.
Output:
Not applicable.
Solution:
public class interation_factorial { static int factorial(int n ) { int f = 1 ; for (int i =n;i>=1;i--) { f*=i; } return f; } public static void main(String[] args) { System.out.println(factorial(5)); } }
No comments :
Post a Comment