Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dadaproject.company;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the number:");
- int input1 = input.nextInt();
- int req = factorial(input1);
- System.out.println("The factorial of "+input1+ " is " + req);
- }
- static int factorial(int input1) {
- int result;
- if (input1 == 0) {
- return 1;
- } else {
- result = factorial(input1 - 1) * input1;
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement