-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path22_Methods
More file actions
54 lines (51 loc) · 1.02 KB
/
22_Methods
File metadata and controls
54 lines (51 loc) · 1.02 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// method = a block of code that is executed whenever it is called upon
1.
public class Main {
public static void main(String[] args) {
hello();
hello();
}
static void hello() {
System.out.println("Hello");
}
}
>>
Hello
Hello
2. Parameters
public class Main {
public static void main(String[] args) {
String name = "Bro";
int age = 21;
hello(name,age);
}
static void hello(String name, int age) {
System.out.println("Hello "+ name + ", you are "+age);
}
}
>>
Hello Bro, you are 21
3.
public class Main {
public static void main(String[] args) {
int x = 3;
int y =4;
int z = add(x,y);
System.out.println(z);
}
static int add(int x, int y){
int z = x + y;
return z;
}
}
oR
public class Main {
public static void main(String[] args) {
int x = 3;
int y =4;;
System.out.println(add(x,y));
}
static int add(int x, int y){
return x+y;
}
}