In mathematical calculations, it is often required to fetch the angles while measuring the objects. In such a situation, transformation from radian to degree in Java comes into effect in the case of analyzing the retrieved measurements with precision.
How to Use the “toDegrees()” Method in Java?
The “Math.toDegrees()” method converts/transforms an angle in radians into the corresponding equivalent angle in degrees.
Note: The transformation from radians to degrees is not exact.
Syntax
double toDegrees(double x)
In this syntax, “x” refers to the angle in radians which need to be converted into degrees.
Return Value
It retrieves the angle measurement as degrees.
Important Considerations
- If the passed argument is NaN, this method retrieves NaN.
- If the passed argument is zero, this method retrieves zero having the same sign.
- If the passed argument is infinity, this method retrieves infinity having the same sign.
Example: Applying the “toDegrees()” Method in Java
The following code example applies the “toDegrees()” method to convert an angle in radians to an equivalent angle in degrees:
public class Degree {
public static void main(String args[]){
double a = Math.PI;
double x = -1.0/0;
double y= 0;
System.out.println("Degree Value -> "+Math.toDegrees(a));
a = (Math.PI) / 2;
System.out.println("Degree Value -> "+Math.toDegrees(a));
System.out.println("Returned Value -> "+Math.toDegrees(x));
System.out.println("Returned Value -> "+Math.toDegrees(y));
}}
According to the above code lines, perform the below-stated steps:
- Initialize the “Math.PI” value to be converted into an angle in degrees.
- Note: “Math.PI -> 180”.
- After that, initialize the stated double values to analyze the return type of the method.
- Also, divide the “Math.PI” value by “2” to return the corresponding angle.
- Lastly, apply the “toDegrees()” method to convert the defined double value containing the angle in radians into an angle in degrees.
- Also, apply the discussed method on the other two values to return the same outcome against the specified “infinity” and “zero” values with the same signs.
Output

This outcome implies that the corresponding equivalent angle is retrieved and the returned values are also identical to the specified ones as per the discussed considerations.
Conclusion
The “Math.toDegrees()” method converts/transforms an angle in radians into the corresponding equivalent angle in degrees. This method returns “zero” and “infinity” is passed the same with the same sign as well.