factorial number in java
int num1 = 6;
int num2 = 1;
for(int a = 1; a<=num1; a++) {
num2 = num2 * a;
}
System.out.println(num2);
factorial number in java
int num1 = 6;
int num2 = 1;
for(int a = 1; a<=num1; a++) {
num2 = num2 * a;
}
System.out.println(num2);
Factorial program in java
// Factorial program using recursion
public class FactorialRecursion
{
public static void main(String[] args)
{
int factorial = 1;
int number = 6;
factorial = factorialFunction(number);
System.out.println("Factorial of " + number + " is : " + factorial);
}
static int factorialFunction(int num)
{
if(num == 0)
{
return 1;
}
else
{
return(num * factorialFunction(num - 1));
}
}
}
recursion factorial java
public class Factorial {
public static void main(String[] args) {
int num = 6;
long factorial = multiplyNumbers(num);
System.out.println("Factorial of " + num + " = " + factorial);
}
public static long multiplyNumbers(int num)
{
if (num >= 1)
return num * multiplyNumbers(num - 1);
else
return 1;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us