27/02/2023

Factorial Program in Java Using For Loop | Factorial in Java

Write a factorial program in java using For loop. In mathematics, the factorial of a non-negative integer n, denoted by n! is the product of all positive integers less than or equal to n. How to find the factorial of a number in java or what is the Factorial of a number in java.

Factorial Program in Java

For example Java Factorial Program

5! = 5 * 4 * 3 * 2 * 1 = 120.

The value of 0! is 1, according to the convention for an empty product * The factorial operation is encountered in many areas of mathematics, notably in combinatorics, algebra, and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of the set of objects). This fact was known at least as early as the 12th century, to Indian scholars. Source: Wikipedia


See Also: C Program To Calculate Factorial Of A Given Number

Factorial Program in Java Source Code


import java.util.Scanner;
import java.io.*;

/* Factorial Program in Java Using For Loop */

public class factjava {

	public static void main(String args[]) {
		int fact = 1, num, i;
		Scanner sc = new Scanner(System.in);

		System.out.print("Enter The Number That You Want Factorial : \n\n");
		num = sc.nextInt();

		for (i = 1; i <= num; i++) {
			fact = fact * i;
		}

		System.out.print("\nFactorial Is = " + fact);
	}
}

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: