Java .toDegrees()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 31, 2022
Contribute to Docs

The .toDegrees() method converts an angle, measured in radians, to an approximately equivalent angle, measured in degrees.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

Syntax

Math.toDegrees(angle)

The data type of the angle parameter and return value of the .toDegrees() method is a double.

Some edge cases for the .toDegrees() method include the following:

  • If the argument is NaN, this method will return NaN.
  • If the argument is zero, this method will return zero with the same sign as the argument.
  • If the argument is infinity, this method will return infinity with the same sign as the argument.

Example

The following example demonstrates the .toDegrees() method being applied to two variables:

// TestDegree.java
public class TestDegrees {
public static void main(String args[]) {
double x = 0.5235987756;
System.out.println(Math.toDegrees(x));
double y = 1.0471975512;
System.out.println(Math.toDegrees(y));
}
}

This results in the following output:

30.0
60.0

All contributors

Contribute to Docs

Learn Java on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours