-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay24_prob1.java
More file actions
46 lines (33 loc) · 876 Bytes
/
Day24_prob1.java
File metadata and controls
46 lines (33 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Create a method named ‘factorial’ in your program that will display the factorial of any given number. factorial of an integer is the product of numbers ranging from 1 to N
Input Format
A single interger that represents the number whose factorial you need to find
Constraints
1<=N<=10
Output Format
Displays the output of number N
Sample Input 0
2
Sample Output 0
2
*/
// kirtan jain
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Recursive {
//Recursive Method
static int factorial (int n)
{
if(n<=1)
return 1;
return (n * factorial(n-1));
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int n = sc.nextInt();
int res = factorial(n);
System.out.print(res);
}}