Home >>Java Math Methods >Java Math.toDegrees() method

Java Math.toDegrees() method

Java Math.toDegrees() method

Java Math.toDegrees() method in Java Math is a built-in math function in java which is used to convert an angle measured in radians to an approximately equivalent angle measured in degrees.

Syntax

public static double toDegrees(double x)  

Parameter

x = It is used for an angle, in radians

Return

It is used to returns the measurement of the angle x in degrees.

  1. This method returns NaN if the argument is NaN.
  2. When the argument is negative, the formula returns negative with the same sign as the argument.
  3. If the argument is infinity, with the same sign as the statement this process will return infinity.

Java Math.toDegrees() method Example 1


public class MyClass  
{  
public static void main(String[] args)   
{  
double a = Math.PI;  
System.out.println(Math.toDegrees(a));  
}  
}  

Output:
180.0

Java Math.toDegrees() method Example 2


public class MyClass  
{  
public static void main(String[] args)   
{  
double a = (Math.PI)/2;  
System.out.println(Math.toDegrees(a));  
}  
}

Output:
90.0