FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/src/main/java/com/examplehub/basics/Function.java at master · JavaCimcoz/Java · GitHub
JavaCimcoz
/
Java
Public
forked from
examplehub/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
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
Java
/
src
/
main
/
java
/
com
/
examplehub
/
basics
/
Function.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
112 lines (88 loc) · 2.02 KB
Breadcrumbs
Java
/
src
/
main
/
java
/
com
/
examplehub
/
basics
/
Function.java
Copy path
File metadata and controls
112 lines (88 loc) · 2.02 KB
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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package
com
.
examplehub
.
basics
;
public
class
Function
{
public
static
void
main
(
String
[]
args
) {
Function
function
=
new
Function
();
/*
* Hello World
*/
function
.
sayHello
();
/*
* My name is Java
*/
function
.
printInfo
(
"Java"
);
/*
* My name is Java. My age is 20
*/
function
.
printInfo
(
"Java"
,
20
);
/*
* 2^2 = 4
*/
System
.
out
.
println
(
"2^2 = "
+
function
.
square
(
2
));
/*
* 10^2 = 100
*/
System
.
out
.
println
(
"10^2 = "
+
function
.
square
(
10
));
/*
* sum(3, 4) = 7
*/
System
.
out
.
println
(
"sum(3, 4) = "
+
function
.
sum
(
3
,
4
));
/*
* sum(1, 2, 3) = 6
*/
System
.
out
.
println
(
"sum(1, 2, 3) = "
+
function
.
sum
(
1
,
2
,
3
));
/*
* sum(1, 2, 3, 4) = 10
*/
System
.
out
.
println
(
"sum(1, 2, 3, 4) = "
+
function
.
sum
(
1
,
2
,
3
,
4
));
/*
* sum(1.5, 2.3) = 3.8
*/
System
.
out
.
println
(
"sum(1.5, 2.3) = "
+
function
.
sum
(
1.5f
,
2.3f
));
/*
* sum(1.5, 2.3) = 3.8
*/
System
.
out
.
println
(
"sum(1.5, 2.3) = "
+
function
.
sum
(
1.5
,
2.3
));
/*
* 1! = 1
*/
System
.
out
.
println
(
"1! = "
+
function
.
factorial
(
1
));
/*
* 5! = 120
*/
System
.
out
.
println
(
"5! = "
+
function
.
factorial
(
5
));
}
public
void
sayHello
() {
System
.
out
.
println
(
"Hello World"
);
}
public
void
printInfo
(
String
name
) {
System
.
out
.
println
(
"My name is "
+
name
);
}
public
void
printInfo
(
String
name
,
int
age
) {
System
.
out
.
println
(
"My name is "
+
name
+
". My age is "
+
age
);
}
public
int
square
(
int
a
) {
return
a
*
a
;
}
public
int
sum
(
int
a
,
int
b
) {
return
a
+
b
;
}
public
int
sum
(
int
a
,
int
b
,
int
c
) {
return
a
+
b
+
c
;
}
public
int
sum
(
int
a
,
int
b
,
int
c
,
int
d
) {
return
sum
(
a
,
b
) +
sum
(
c
,
d
);
}
public
float
sum
(
float
a
,
float
b
) {
return
a
+
b
;
}
public
double
sum
(
double
a
,
double
b
) {
return
a
+
b
;
}
public
int
factorial
(
int
n
) {
int
fact
=
1
;
for
(
int
i
=
1
;
i
<=
n
;
i
++) {
fact
*=
i
;
}
return
fact
;
}
}
Back
|
FazBrowse Home
|
New Git URL