FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaExamples/MethodsDemo.java at master · alimogh/JavaExamples · GitHub
alimogh
/
JavaExamples
Public
forked from
CMPundhir/JavaExamples
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaExamples
/
MethodsDemo.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
37 lines (37 loc) · 826 Bytes
Breadcrumbs
JavaExamples
/
MethodsDemo.java
Copy path
File metadata and controls
37 lines (37 loc) · 826 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
);
}
}
Back
|
FazBrowse Home
|
New Git URL