You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's the iterative approach to finding factorial of a number in java:-
public class FactorialIterative {
public static long factorialIterative(int n) {
long result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
return result;
}
public static void main(String[] args) {
int number = 5;
long result = factorialIterative(number);
System.out.println("The factorial of " + number + " is: " + result);
}
}
Write an algorithm to find factorial of a number entered by user in Java
The text was updated successfully, but these errors were encountered: