Computer Science, asked by tanumukherjee79, 7 months ago

Wap in java to input an integer and finds its factorial of a number is the product of all natural numbers till that number.

For Ex= 5= 5*4*3*2*1 = 120

Plz give the answer ill mark u brainlist...
Plz give the answer..I am requesting..
This is Computer​

Answers

Answered by Oreki
1

import java.util.Scanner;

public class Factorial {

// Calculating the factorial using recursion.

static long factorial(long number) {

return (number = = 0) ? 1 : (number * factorial(number - 1));

}

public static void main(String[ ] args) {

System.out.print("Enter a number - ");

System.out.println("Factorial - " + factorial(new Scanner(System.in).nextLong( )));

}

}

Similar questions