The java.lang.Math.toDegrees(double angrad) converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.
Here, the argument angrad is in radians.
Example
Following is an example to implement toDegrees() method in Java −
import java.lang.*;
public class Demo {
public static void main(String[] args) {
double x = 45;
double y = -180;
x = Math.toDegrees(x);
y = Math.toDegrees(y);
System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x));
System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y));
}
}Output
Math.tanh(2578.3100780887044)=1.0 Math.tanh(-10313.240312354817)=-1.0
Example
Let us see another example −
import java.lang.*;
public class Demo {
public static void main(String[] args) {
double x;
x = Math.PI;
System.out.println(Math.toDegrees(x));
}
}Output
180.0