Java .toDegrees()
Anonymous contributor
Published Oct 31, 2022
The .toDegrees() method converts an angle, measured in radians, to an approximately equivalent angle, measured in degrees.
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 returnNaN. - If the argument is
zero, this method will returnzerowith the same sign as the argument. - If the argument is
infinity, this method will returninfinitywith the same sign as the argument.
Example
The following example demonstrates the .toDegrees() method being applied to two variables:
// TestDegree.javapublic 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.060.0
All contributors
- Anonymous contributor
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