We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 0d8e345 + 066b898 commit 4a5729cCopy full SHA for 4a5729c
factorial/Factorial.java
@@ -0,0 +1,26 @@
1
+import java.util.Scanner;
2
+/**
3
+ * Created by buddhimah on 10/16/2017.
4
+ */
5
+public class Factorial {
6
+ public static int fac(int number){
7
+ int r;
8
+ if(number == 1){
9
+ return 1;
10
+ }
11
+ r = fac(number - 1)*number;
12
+ return r;
13
14
+ public static void main(String args[]){
15
+ Scanner sc = new Scanner(System.in);
16
+ System.out.println("Enter a number: ");
17
+ int num =sc.nextInt();
18
+ if(num < 0){
19
+ Error a = new Error("factorial for negative numbers is undefined");
20
+ System.out.println(a.getMessage());
21
+ Factorial.main(new String[1]);
22
+ }else {
23
+ System.out.println(fac(num));
24
25
26
+}
0 commit comments