Java Examples

100+ tutorials, source code, and examples to help you develop creative and technical skills.

Java Program to find Factorial of a number using for loop

FactorialForLoop.java

import java.util.Scanner;

/* Code From Learnoset - Learn Coding Online.
    Download Learnoset App from PlayStore to learn coding,
    projects, algorithms, error handling
 */
 
 // Java Program to find Factorial of a number using for loop
public class FactorialForLoop {

    public static void main(String args[]) {

        // create Scanner class object to get input from user
        Scanner scanner = new Scanner(System.in);
		
        System.out.println("Enter a number:");
		
        //get user's enetered value from 'scanner' object into 'num' variable
        int num = scanner.nextInt();
		
		// declared 'factorial' variable to store factorial
        int factorial = 1;
		
		// gettting factorials using 'for loop'
		for(int i = 1; i <= num; i++){
			factorial = factorial * i;
		}        
		
        System.out.println("Factorial of "+num+" is = " + factorial);

    }	

}

Projects with Source Code + Video Tutorials

You can download our Java and Android Studio Projects with Source Code and Video Tutorials.

Gamer-Bazi---Tournament-Application-with-Admob-Ads-&-Web-Admin-Panel
Gamer Bazi - Tournament Application with Admob Ads & Web Admin Panel
Login-and-Register-Activity-Material-UI-design-in-Android-Studio
Login and Register Activity Material UI design in Android Studio
Login-&-Register-Screen-UI-Design---02
Login & Register Screen UI Design - 02

If you have any Questions or Queries
You can mail us at info.learnoset@gmail.com

Follow us to learn Coding and get in touch with new Technologies.