answersLogoWhite

0

If you're talking about factorial as in "4! = 4 * 3 * 2 * 1 = 24" then you could make a function something like this:

public int fact(int Num) {

int fact;

for (int i = Num; i > 1; i--) {

fact = i * (i - 1)

}

Return fact;

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

Jntu 2-2 oops through java answers?

write a java program to find factorial using recursive and non recursive


What is a factorial loop?

An example in Java, to compute 10!: int factorial = 1; for(int i = 1; i < 11; i++) { factorial *= i; }


Write a program in java to find factorial of a number?

I suggest to use a for loop, more or less like this (assuming the parameter is "n"): product = 1; for (int i = 1; i <= n; i++) { product *= i; }


Why factorial is not a valid identifier in Java?

It's been a little while since I've learned Java, but the exclamation point used to denote factorials (!) is already used in Java to denote a negation (e.g. a != 2 means a is not equal to 2). To create a factorial in Java, construct a for loop and multiply all the consecutive integers.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


A program for simple factorial in prolog?

In Prolog, a simple factorial program can be defined using recursion. Here's a basic implementation: factorial(0, 1). % Base case: factorial of 0 is 1 factorial(N, Result) :- N > 0, N1 is N - 1, factorial(N1, Result1), Result is N * Result1. % Recursive case You can query the factorial of a number by calling factorial(N, Result). where N is the number you want to compute the factorial for.


Write a program in java for factorial?

// Iterative solution public static final long iterativeFactorial(final long n) { long factorial = 1; for (long i = 1; i <= n; i++) { factorial *= i; } return factorial; } // Recursive solution public static final long recursiveFactorial(final long n) { if (n <= 1) { return n; } return n * recursiveFactorial(n - 1); } // Arbitrary length solution - may take a while, but works on any positive number. public static final BigInteger factorial(final BigInteger n) { BigInteger factorial = BigInteger.ONE; for (BigInteger i = BigInteger.ONE; i.compareTo(n) <= 0; i = i.add(BigInteger.ONE)) { factorial = factorial.multiply(i); } return factorial; }


What is java program on computers?

#!/usr/bin/perl print 'java program';


What is java virtucal mechine?

That refers to the program that runs the compiled Java program.


What powder game doesnt need java?

Any program written for the Java technology needs Java. Any program NOT written for Java DOESN'T need it.


C program to find factorial of a no?

this is a code for calculating it recursivelly: float Factorial (float n) { if (n<=1) return 1.0; else return n* Factorial(n-1); }


Java Track?

Java Track is the java training program offered by SynergisticIT