Factorial

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

Comments (0)

  • To add your comment please or

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

Got It!