-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethods.java
More file actions
39 lines (32 loc) · 889 Bytes
/
Methods.java
File metadata and controls
39 lines (32 loc) · 889 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
36
37
38
39
//Two types of Methods in java
//Predefined method
//User-defined method
//###########################predefined method ######################################
public class Methods
{
public static void main(String[] args)
{
System.out.println("The Largest Number is: "+Math.max(80, 40));
}
}
//##########################User-defined method #####################################
import java.util.Scanner;
public class Methods
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Number: ");
int n = sc.nextInt();
findFactorial(n);
}
public static void findFactorial(int n)
{
int f = 1;
for(int i = 1; i <= n; i++)
{
f = f * i;
}
System.out.println("The Factorial of "+n+" is: "+f);
}
}