public class Factorial {

public static void main(String args[]) {

int n, c, fact = 1;

System.out.println(“Enter an integer to calculate it’s factorial”);

Scanner in = new Scanner(System.in);

n = in.nextInt();

if (n < 0) System.out.println("Number should be non-negative."); else { for (c = 1; c <= n; c++) fact = fact * c; System.out.println("Factorial of " + n + " is = " + fact); } } } import java.util.Scanner; public class FactorialCalculatorApp { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int number, factorial; //Welcome the user and prompt for input System.out.println("Welcome to the Factorial Calculator"); System.out.print("Enter an integer from 1 to 10: "); number = sc.nextInt(); //calculate and display factorial value factorial = calculateFactorial(number); System.out.println(number + "! = " + factorial); }//end of main method*/ public static int calculateFactorial(int n) { int factorial = 1; for (int i = 2; i <= n; i++) { factorial *= i; } return factorial; }//end of calculateFactorial method*/ }//end of class public class Factorial { public static void main(String args[]){ int i,fact=1; int number=5;//It is the number to calculate factorial for(i=1;i<=number;i++){ fact=fact*i; } System.out.println("Factorial of "+number+" is: "+fact); } } import java.util.Scanner; public class FactorialProgram { public static void main(String[] args) { int number, factorial; Scanner scan=new Scanner(System.in); System.out.print("Enter a number to calculate it's factorial : "); number=scan.nextInt(); factorial=fact(number); //calling method fact() System.out.println("Factorial of "+number+" is: "+factorial); } static int fact(int n) { //method which calculates factorial of a number using recursion int output; if(n==1){ return 1; } //termination condition of recursion method, i.e., when to stop calling a method output = fact(n-1)* n; //calling same method again and again with new arguments (i.e., decremented value), until it reaches to termination condition return output; //returning final value of output, when execution comes out from recursion method call stack/frame, i.e., when recursion stops } } import java.util.Scanner; class factorial { public static void main(String args[]){ int i,n,fact=1; System.out.println("Enter a number"); Scanner in = new Scanner(System.in); n=in.nextInt(); for(i=1;i<=n;i++){ fact=fact*i; } System.out.println("Factorial of "+n+" is: "+fact); } } import java.util.Scanner; public class FactorialExample { public static void main(String[] args) { //create scanner object to input data Scanner scanner = new Scanner(System.in); System.out.println("Enter the number for finding factorial: "); int num = scanner.nextInt(); int factorial = 1; for (int i=1;i<=num;i++) { factorial = factorial*i; } System.out.println("Factorial of "+num+" is :"+factorial); } } import java.util.Scanner;

Tomy

Tomy is a contributor at AskMeCode. We are committed to providing well-researched, accurate, and valuable content to our readers.

You May Also Like

Artistic representation for The Imperative of Register Management in System-on-Chip (SoC) Design

The Imperative of Register Management in System-on-Chip (SoC) Design

Challenges in Register Management Engineering teams face numerous challenges in managing registers in SoC design. Inconsistencies in register descriptions can...

Why Does a C Program Exit with a Return Code of 0xC00000FD? How to Solve and Fix

Why Does a C Program Exit with a Return Code of 0xC00000FD? How to Solve and Fix

Ever faced this weird error 0xC00000FD in C program? This article explains why it occurs and how you can fix...

Why Your Code is So Big? Let It Be, Before It Creeps Up

Why Your Code is So Big? Let It Be, Before It Creeps Up

[CodeHub](http://blog.codehub.com/) is a blog around managing and reducing the size of your code base. The size of your code base...

blockly is an easy to learn visual block-based programming language. You can use it to build simple games, interactive stories, and animations.

blockly is an easy to learn visual block-based programming language. You can use it to build simple games, interactive stories, and animations.

Blockly is an easy to learn visual block-based programming language. You can use it to build simple games, interactive stories,...

Leave a Reply

About | Contact | Privacy Policy | Terms of Service | Disclaimer | Cookie Policy
© 2026 AskMeCode. All rights reserved.