Java Math toDegrees()
toDegrees() accepts double value as an argument, which is angle in radians.
toDegrees() computes the number of degrees for the given radians and returns the value as double datatype.
Following is the syntax of toDegrees() method.
double degrees = toDegrees(double radians)
Since the definition of toDegrees() function has double datatype as argument, you can pass int, float or long as arguments as these datatypes will implicitly promote to double.
Example 1 – Math.toDegrees(double)
In the following example, we pass angle in radians as argument to toDegrees() method and find the degrees for the given radians.
Java Program
public class MathExample {
public static void main(String[] args) {
double angle_radians = 1;
double angle_degrees = Math.toDegrees(angle_radians);
System.out.println(angle_degrees);
}
}
Output
57.29577951308232
Example 2 – Math.toDegrees(int)
In the following example, we pass an int value for the argument to toDegrees() method.
Java Program
public class MathExample {
public static void main(String[] args) {
int angle_radians = 5;
double angle_degrees = Math.toDegrees(angle_radians);
System.out.println(angle_degrees);
}
}
Output
286.4788975654116
Similarly, you can provide a float or long value as argument to toDegrees() method.
Conclusion
In this Java Tutorial, we learned about Java Math.toDegrees() function, with example programs.