Answers for "Factorial from 1 to 10 in java"

1

Factorial from 1 to 10 in java

// Factorial from 1 to 10 in java
public class FactorialFrom1To10
{
   public static void main(String[] args)
   {
      int count;
      long factorial = 1;
      System.out.printf("%4s%30s\n", "Number", "Factorials");
      for(count = 1; count <= 10; count++)
      {
         factorial *= count;
         System.out.printf("%4d%,30d\n", count, factorial);
      }
   }
}
Posted by: Guest on February-18-2021
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
0

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

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language