Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e596e42

Browse files
Merge pull request #4 from starmayank07/master
Adding Factorial Program
2 parents 36c8ace + 256718b commit e596e42

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎Basic-Programs/factorial.java‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import java.util.Scanner;
2+
3+
class Factorial
4+
{
5+
public static void main(String args[])
6+
{
7+
int n, c, f = 1;
8+
9+
System.out.println("Enter an integer to calculate its factorial");
10+
Scanner in = new Scanner(System.in);
11+
12+
n = in.nextInt();
13+
14+
if (n < 0)
15+
System.out.println("Number should be non-negative.");
16+
else
17+
{
18+
for (c = 1; c <= n; c++)
19+
f = f*c;
20+
21+
System.out.println("Factorial of "+n+" is = "+f);
22+
}
23+
}
24+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /