Fri Aug 27 2021

Factorial

File Name: factorial.java

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

class calculating {

	/* Constructor of the class */
	calculating(int no) {
		int f = 1;

		/* Loop the process using 'while' */
		while(no >= 1) {
			f = no * f;
			no = no - 1;
			a = a / 10;
		}
		System.out.println("Factorial: "+f);
	}
}
										
class factorial {
	public static void main(String args[ ]) {

		/* Create object of the Scanner */
		Scanner r = new Scanner(System.in);
		System.out.println("Program to calculate factorial");
		System.out.println("Enter a number:");

		/* Received data from user using scanner object and pass value to the constructor of the class */
		calculating cal = new calculating(Integer.parseInt(r.nextLine()));	
	}
}



/* Output */
Program to calculate factorial
Enter a number:
5

Factorial: 120
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.