FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaTutorial/src/F012_TheMathClass.java at master · windweb/JavaTutorial · GitHub
windweb
/
JavaTutorial
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaTutorial
/
src
/
F012_TheMathClass.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (24 loc) · 1.53 KB
Breadcrumbs
JavaTutorial
/
src
/
F012_TheMathClass.java
Copy path
File metadata and controls
32 lines (24 loc) · 1.53 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
public
class
F012_TheMathClass
{
public
static
void
main
(
String
[]
args
) {
int
result
=
Math
.
round
(
1.1F
);
// Округлить до целого
System
.
out
.
println
(
result
);
// 1
int
result2
= (
int
)
Math
.
ceil
(
1.1F
);
// Округлить вверх
System
.
out
.
println
(
result2
);
// 2
int
result3
= (
int
)
Math
.
floor
(
1.1F
);
// Округлить вниз
System
.
out
.
println
(
result3
);
// 1
int
result4
= (
int
)
Math
.
max
(
1
,
2
);
// Максимальное значение
System
.
out
.
println
(
result4
);
// 2
double
result5
=
Math
.
random
();
// Случайное число в диапазоне от 0 до 1 с дробной частью
System
.
out
.
println
(
result5
);
// 0.4368805334217625
double
result6
=
Math
.
random
() *
100
;
// Случайное число в диапазоне от 0 до 100 с дробной частью
System
.
out
.
println
(
result6
);
// 49.123
int
result7
= (
int
)
Math
.
round
(
Math
.
random
() *
100
);
// Случайное число в диапазоне от 0 до 100 с округлением до целого
System
.
out
.
println
(
result7
);
// 49
// но
int
result8
= (
int
)
Math
.
random
() *
100
;
// всегда 0
System
.
out
.
println
(
result8
);
// всегда = 0
// однако
int
result9
= (
int
) (
Math
.
random
() *
100
);
// Случайное число в диапазоне от 0 до 100 с округлением до целого
System
.
out
.
println
(
result9
);
// 49
}
}
Back
|
FazBrowse Home
|
New Git URL