- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMethodsDemo.java
More file actions
Latest commit
37 lines (37 loc) · 826 Bytes
/
Copy pathMethodsDemo.java
File metadata and controls
37 lines (37 loc) · 826 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
//why we use methods?
//1.code reusability
//2.makes our program easy to write and understand with clean code
classMethodsDemo{
publicstaticvoidshow(){
System.out.println("Bakwaasaassssss");
}
publicstaticintadd(){
return2+5;
}
publicstaticintmul(inta,intb){
returna*b;
}
//arr[]
publicstaticintaverage(int[] arr){
intnumOfSub = arr.length;
inttotalMarks = 0;
for(intmarks : arr){
totalMarks = totalMarks + marks;
}
intavg = totalMarks/numOfSub;
returnavg;
}
publicstaticvoidmain(String[] args){
show();
inta = add();
System.out.println(a);
intb = mul(7,2);
System.out.println(b);
int[] arr = {100,89,98,90,32};
intavg = average(arr);
System.out.println(avg);
int[] arr2 = {0,5,7,12,16};
intavg2 = average(arr2);
System.out.println(avg2);
}
}