-
Notifications
You must be signed in to change notification settings - Fork 1
/
09_Methods in java
68 lines (58 loc) · 1.52 KB
/
09_Methods in java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
public class Methods {
static void food(){
System.out.println("salam valikum");
}
static void food(int a){
System.out.println("salam valikum " + a + " bhaijaan");
}
static void change(int a){
a = 93;
}
static void change2(int [] arr){
arr[0]=98;
}
static void boy(){
System.out.println("Girl");
}
static int logic(int x, int y){
int z;
if (x>y){
z = x+y;
}
else {
z = (x+y)*5;
}
return z;
}
public static void main(String[] args) {
int a = 9;
int b = 7;
int c;
// Method invocation using object creation
// Methods obj = new Methods();
c = logic(a, b); // Use obj.class_name while using object creation
int a1 = 3;
int b1 = 4;
int c1;
c1 = logic(a1, b1); // Use obj.class_name while using object creation
System.out.println(c);
System.out.println(c1);
// boy();
int[] x = {29,48,49,33};
// int x= 46;
//change(x);
//System.out.println("X : "+x);
//int[] marks = {29,48,49,33};
//change2(marks);
//System.out.println("X : "+ marks[0]);
// Method Overloading
food(0);
int i;
int fact=1;
int n = 6;
for (i = fact;i<=n;i++){
fact = fact*n;
}
System.out.println("Factorial is = " +fact);
}
}