Advertisement
chiplu

Java factorial

Nov 17th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. package dadaproject.company;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         System.out.println("Enter the number:");
  9.         int input1 = input.nextInt();
  10.         int req = factorial(input1);
  11.         System.out.println("The factorial of "+input1+ " is " + req);
  12.     }
  13.  
  14.     static int factorial(int input1) {
  15.         int result;
  16.         if (input1 == 0) {
  17.             return 1;
  18.         } else {
  19.             result = factorial(input1 - 1) * input1;
  20.             return result;
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement