Advertisement
danh8569

Factorial

Oct 10th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.37 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Factorial {
  4.  
  5.     public static void main(String[] args) {
  6.         int factorial = 1;
  7.  
  8.         Scanner in = new Scanner(System.in);
  9.  
  10.         System.out.println("Enter A Number:");
  11.         int number = in.nextInt();
  12.  
  13.         int i = 1;
  14.  
  15.         while (i <= number) {
  16.             factorial *= i;
  17.             i++;
  18.         }
  19.  
  20.         System.out.println("Factorial is = " + factorial);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement