 Hello friends, I am Sanjay Gupta. I welcome you on my channel. If you like this video, you can subscribe my YouTube channel. In this video, I am going to demonstrate you how you can calculate factorial in Java. First of all, I am going to import a package whose name is util. Inside this package, a predefined class is available. That is scanner. This scanner class is required to read inputs from user. That's why I have imported this class. Now I am going to define another class whose name is fact. Inside this class defining main function or main method. So inside main method, I'm going to calculate or I'm going to implement logic for calculating factorial. So I'm declaring three variables here and I and f f is initialized with one because I will be using this variable for multiplication. So whenever we use a particular variable for multiplication, then we initialize it with one. Now I am creating instance of scanner class that is input. Here in the constructor I am passing system.in. It means all the input will be received from user through this input instance and through user from console to read input. First I am going to display the message enter number whose factorial user want to calculate. So that number will be stored inside n variable and the method next in will be receiving that number from the user. After reading that number, I have to implement a for loop so that I can calculate its factorial. So for loop is initialized with one condition is I less than equals to n and increment is I plus plus. So this loop will repeat n times and f equals to f into I will be calculated. So after complete rotation or complete iteration of this for loop. I can print the result on output screen. So the system.out.println will display calculated factorial on output screen. This file is saved with fact or Java name. So after complete typing or complete implementation, I have saved this code. Now I need to compile this code. So I am opening command prompt. This code is saved in D drive and inside D drive Java folder. So right now I am in the Java folder. Now I can compile this code with the help of Java C command. So I have entered Java C space fact dot Java. You can see it is compiled successfully. There is no error in the code. Now I can execute the code using Java space name of class that is fact. It is asking for a number. I am entering five. You can see the result. It is showing factorial equals to 120. So it means factorial is calculated properly and program is working correct. So this way we can implement logic to calculate factorial in Java. I hope you have understood whatever I have explained in this program. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.