-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF012_TheMathClass.java
More file actions
32 lines (24 loc) · 1.53 KB
/
F012_TheMathClass.java
File metadata and controls
32 lines (24 loc) · 1.53 KB
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
}
}