Java Programming

Factorial

Java programming example for calculate factorial of the user given number

8/27/2021
0 views
factorial.javaJava
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
Factorial GeneratorFactorial CalculationJava Tutorial

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com