Answers for "java program to find factorial of a number"

1

java program to find factorial of a number

import java.util.Scanner;
public class FindingFactorial {
    public static void main(String[] args) {
        int num;
        System.out.println("Enter the number: ");
        Scanner in = new Scanner(System.in);
        num = in.nextInt();
        in.close();
        long fact = 1;
        int i = 1;
        while(i<=num)
        {
            fact = fact * i;
            i++;
        }
        System.out.println("Factorial of "+num+" is: "+fact);
    }
}
Posted by: Guest on April-01-2021
1

java program to find factorial of a number

import java.math.BigInteger;

public class Factorial {

    public static void main(String[] args) {

        int num = 30;
        BigInteger factorial = BigInteger.ONE;
        for(int i = 1; i <= num; ++i)
        {
            // factorial = factorial * i;
            factorial = factorial.multiply(BigInteger.valueOf(i));
        }
        System.out.printf("Factorial of %d = %d", num, factorial);
    }
}
Posted by: Guest on April-01-2021
1

Write a program to find factorial of a number using for loop in java

public class Main
{
public static void main(String[] args)
{
int num = 15;
long factorial = 1;
for(int i = 1; i <= num; ++i)
{
factorial = factorial * i;
}
System.out.printf("Factorial of %d is", factorial);
}
}
Posted by: Guest on June-12-2021
1

factorial number in java

int num1 = 6; 
 int num2 = 1;
    for(int a = 1; a<=num1; a++) {
        num2 = num2 * a;
    }
        System.out.println(num2);
Posted by: Guest on June-04-2021
1

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));
      }
   }
}
Posted by: Guest on December-29-2020
1

factorial program in java

public class FactorialDemo
{
   public static void main(String[] args)
   {
      int number = 6, factorial = 1;
      for(int a = 1; a <= number; a++)
      {
         factorial = factorial * a;
      }
      System.out.println("Factorial of " + number + " is : " + factorial);
   }
}
Posted by: Guest on October-25-2020

Code answers related to "java program to find factorial of a number"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language