Java acos() Method
The acos() method returns the arc cosine of the specified double argument.
Syntax
double acos(double d)
Parameters
-
d -- any primitive data type; must be less than 1.
Return Value
Returns the arc cosine of the specified double argument; if the specified argument is greater than 1, returns NaN.
The return value is between 0 and Math.PI.
Example
The following example demonstrates the use of the acos() method:
Example
public
class
RunoobTest
{
public
static
void
main
(
String
args
[
]
)
{
double
degrees
=
45.0
;
double
radians
=
Math
.
toRadians
(
degrees
)
;
System
.
out
.
format
(
"The value of pi is %.4f%n"
,
Math
.
PI
)
;
System
.
out
.
format
(
"The arc cosine of %.4f is %.4f degrees %n"
,
Math
.
cos
(
radians
)
,
Math
.
toDegrees
(
Math
.
acos
(
Math
.
sin
(
radians
)
)
)
)
;
}
}
Compile the above program; the output is:
pi 的值为 3.1416
0.7071 的反余弦值为 45.0000 度
Example
public
class
RunoobTest
{
public
static
void
main
(
String
[
]
args
)
{
// variable
double
a
=
0.5
;
double
b
=
0.79
;
double
c
=
0.0
;
double
d
=
2
;
// Output
System
.
out
.
println
(
Math
.
acos
(
a
)
)
;
// 1.0471975511965979
System
.
out
.
println
(
Math
.
acos
(
b
)
)
;
// 0.6599873293874984
System
.
out
.
println
(
Math
.
acos
(
c
)
)
;
// 1.5707963267948966
System
.
out
.
println
(
Math
.
acos
(
d
)
)
;
// d is greater than 1, so NaN is output
}
}
Compile the above program; the output is:
1.0471975511965979
0.6599873293874984
1.5707963267948966
NaN
The Java Number class