Skip to content

Commit ec43a17

Browse files
committed
feat: Calculate factorial of a number using while loop
🧠 Logic: - Start with `n = 6` and initialize `result = 1`. - Multiply `result` by `n` in each iteration and decrement `n` by 1. - Continue until `n` reaches 0. - This computes `6! = 6×5×4×3×2×1 = 720` and prints the result. Signed-off-by: Somesh diwan <[email protected]>
1 parent 1364e2b commit ec43a17

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Section7ConditionalStatements/src/Factorial.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ public class Factorial {
22
public static void main(String[] args) {
33
int n =6;
44
int result = 1;
5-
while(n>0)
6-
{
7-
result = result *n;
5+
6+
while(n>0) {
7+
result = result * n;
88
n--;
99
}
1010
System.out.println(result);

0 commit comments

Comments
 (0)