Skip to content

Commit d1f6136

Browse files
authored
Create factorial-by-loops.java
1 parent 2fe5975 commit d1f6136

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.company;
2+
3+
import java.util.Scanner;
4+
5+
public class Factorial {
6+
public Factorial() {
7+
}
8+
9+
public static void main(String[] args) {
10+
Scanner in = new Scanner(System.in);
11+
System.out.println("you want factorial of which number");
12+
int n = in.nextInt();
13+
int fact = 1;
14+
15+
for(int i = n; 1 <= i; --i) {
16+
fact *= i;
17+
}
18+
19+
System.out.println("the factorial of " + n + " is " + fact);
20+
}
21+
}

0 commit comments

Comments
 (0)