Java Factorial Calculation

During the Java development phase, from time to time, the question arises how to perform factorial calculation of the number entered.

With these codes, you will be able to easily find the factor of the number entered in the program.


Java Factorial Calculation

Factorial is the name given to the numbers symbolized by an exclamation point on the right side. Multiplication of all numbers starting from 1 to the desired counting numbers is called factorial.

For example, 3 factorials are 3!= 3x2x1 = 6.

It is also possible to algorithmically encode such codes. With a simple for loop logic, you can calculate the factorial you receive from the user.

The code to be included in the for loop is determined as factorial *= i.  System. out. printf ( number, factorical) on the screen by keeping memory of the desired java factor calculation in  the factorial shift; code.

package project;//Do not forget to replace this line with your own package name.

import java.util.Scanner;

public class class {//Do not forget to replace this line with your own class name.

public static void main(String[] args) {

Scanner scan = new Scanner(;

System.out.print(“Enter a Number:”);

int sayi = scan.nextInt();

long faktoriyel = 1;

for(int i = 1;  <= sayi; ++i){

faktoriyel *= i; }

System.out.printf(“%d! = %d \n”, sayi, faktoriyel);




In addition to java-related concepts, there are some examples and sample applications to encourage Java learning, including decision-making and loop controls.

You can also take a look at other examples:

Program that Reverses the Number Entered in Java and Raises It From Large to Small

Program That Finds How Many 1s Between 1 and 100

Harshad Number Program

Palindromic Number

Prime number


If there are any problems with the codes, please contact us in the comments section.


Bir cevap yazın

E-posta hesabınız yayımlanmayacak.

Makale Hizmeti