Skip to content

Commit a1417b5

Browse files
Add files via upload
0 parents  commit a1417b5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

factorial.java

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

0 commit comments

Comments
 (0)