-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfac.java
More file actions
35 lines (22 loc) · 959 Bytes
/
Copy pathfac.java
File metadata and controls
35 lines (22 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// here we will callculate the factorial by the help of loops and function in java //
import java.util.*;
public class fac{ // Here we made a class
public static void printfac(int n) { // after making a class we have ti make a function with condition
if (n<0){
System.out.println("invalid number");
return;
}
int factorial = 1 ;
for(int i = n; i >=1 ; i--){ // this is loop mean the condiion
factorial = factorial*i;
}
System.out.println("your factorial is ::" + factorial);
return ;
}
public static void main(String args[]){ // this is the call function we call the above function after giving the input
// to the computer
Scanner chayan = new Scanner(System.in);
int n = chayan.nextInt();
printfac(n);
}
}