forked from CMPundhir/JavaExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodsDemo.java
More file actions
37 lines (37 loc) · 826 Bytes
/
MethodsDemo.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
class MethodsDemo{
public static void show(){
System.out.println("Bakwaasaassssss");
}
public static int add(){
return 2+5;
}
public static int mul(int a,int b){
return a*b;
}
//arr[]
public static int average(int[] arr){
int numOfSub = arr.length;
int totalMarks = 0;
for(int marks : arr){
totalMarks = totalMarks + marks;
}
int avg = totalMarks/numOfSub;
return avg;
}
public static void main(String[] args){
show();
int a = add();
System.out.println(a);
int b = mul(7,2);
System.out.println(b);
int[] arr = {100,89,98,90,32};
int avg = average(arr);
System.out.println(avg);
int[] arr2 = {0,5,7,12,16};
int avg2 = average(arr2);
System.out.println(avg2);
}
}