-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Math Methods.java
More file actions
76 lines (58 loc) · 1.83 KB
/
Java Math Methods.java
File metadata and controls
76 lines (58 loc) · 1.83 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
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
Java Math has many math methods -------------
such as---------
--Java Math.abs()
--Java Math.acos()
--Java Math.addExact()
--Java Math.asin()
--Java Math.cos()
--Java Math.tan()
--Java Math.sinh()
--Java Math.exp()
--Java Math.loglp()
--Java Math.log()--------and ETC
----------------------------------------The Example-----------------------------------------------------------
----Example the math.abs()---------
class Main {
public static void main(String[] args) {
int a = -35;
long b = -141224423L;
double c = -9.6777777d;
float d = -7.7f;
System.out.println(Math.abs(a));
System.out.println(Math.abs(b));
System.out.println(Math.abs(c));
System.out.println(Math.abs(d));
}
}
----------Example the math.acos()----------
import java.lang.Math;
class Main {
public static void main(String[] args) {
// create variable
double a = 0.5;
double b = 0.79;
double c = 0.0;
// print the arc cosine value
System.out.println(Math.acos(a)); // 1.0471975511965979
System.out.println(Math.acos(b)); // 0.6599873293874984
System.out.println(Math.acos(c)); // 1.5707963267948966
}
}
------------Example the math.log()-------------
class Main {
public static void main(String[] args) {
// compute log() for double value
System.out.println(Math.log(9.0)); // 2.1972245773362196
// compute log() for zero
System.out.println(Math.log(0.0)); // -Infinity
// compute log() for NaN
double nanValue = Math.sqrt(-5.0);
System.out.println(Math.log(nanValue)); // NaN
// compute log() for infinity
double infinity = Double.POSITIVE_INFINITY;
System.out.println(Math.log(infinity)); // Infinity
// compute log() for negative numbers
System.out.println(Math.log(-9.0)); // NaN
}
}
----------And the ETC---------------