Open In App

Java Math toDegrees() Method

Last Updated : 12 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The toDegrees() method comes under the java.lang.Math package. This method is used to convert an angle from radians to its equivalent degrees. This method is useful in mathematical computations where angle conversion is required, for example, trigonometry, geometry etc.

Note: The conversion from radians to degrees is not always exact due to floating point precision. The users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Syntax of toDegrees() Method

public static double Math.toDegrees(double rad)

  • Parameter: rad: This parameter is an angle in radians which we want to convert in degrees.
  • Returns: It returns the corresponding angle in degrees as a double.

Important Points:

  • This toDegrees() method belongs to Java Math class.
  • This method accepts a double and returns a double.
  • This method can handle both positive and negative angles.
  • For reverse conversion, use Math.toRadians() method.

Examples of Java Math toDegrees() Method

Example 1: In this example, we will convert the standard radian values to degrees.

Java
// Java program to demonstrate toDegrees() method
import java.lang.Math;

public class Geeks {

    public static void main(String[] args) {
        double r1 = Math.PI;        
        double r2 = Math.PI / 2;   
        double r3 = Math.PI / 4;    

        System.out.println(Math.toDegrees(r1));
        System.out.println(Math.toDegrees(r2));
        System.out.println(Math.toDegrees(r3));
    }
}

Output
180.0
90.0
45.0


Example 2: In this example, we are trying to convert the negative radians into degrees.

Java
// Java program to convert negative radians
// using toDegrees() method
import java.lang.Math;

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

Output
-90.0

Explanation: Negative radian is correctly converted into the equivalent negative degree.


Example 3: In this example, we will take the user input for radians, and then use toDegrees() method to convert it into the degree.

Java
// Java program to take user input for radian
// then convert into degree
import java.util.Scanner;
import java.lang.Math;

public class Geeks {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter angle in radians: ");
        double r = sc.nextDouble();
        System.out.println("In degrees: " + Math.toDegrees(r));
    }
}

Output:

Output

Next Article
Practice Tags :

Similar Reads