Advertisement
Vladkoheca

FactorialCalculation.java

Oct 24th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.45 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2. public class FactorialCalculation {
  3.     public static void main(String[] args) {
  4.         Scanner sc = new Scanner(System.in);
  5.  
  6.         System.out.print("Enter a number: ");
  7.         int z = 0;
  8.         int n = sc.nextInt();
  9.         z = n;
  10.         long factorial = 1;
  11.         for (int i = 1; i <= n; n--) {
  12.             factorial *= n;
  13.         }
  14.         System.out.println("The factorial of " + z + " is: " + factorial);
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement