Java Math toDegrees()

Learn via video course
FREE
View all courses
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Java Course - Mastering the Fundamentals
Java Course - Mastering the Fundamentals
by Tarun Luthra
1000
5
Start Learning
Topics Covered

Overview

An angle measured in radians can be converted to an approximately equivalent angle in degrees using the toDegrees() method defined in the Math class.

  • toDegrees() method returns NaN if the argument is NaN(Not a Number).
  • toDegrees() method returns zero with the same sign as the argument if the argument is zero.
  • toDegrees() method returns Infinity with the same sign as the input if the argument is Infinity.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Syntax of Math toDegrees()in Java

The syntax of the toDegrees() method is:

Parameters of Math toDegrees() in Java

The toDegrees() method takes only one parameter.

  • angle: The angle in radians that needs to be changed to degrees.

Return Value of Math toDegrees() in Java

  • Returns the angle measured in degrees
  • Return type is double
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Exceptions of Math toDegrees() in Java

Math.toDegrees() does NOT throw any exception.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example

Note: To convert an angle in radians to degrees we simply multiply it with 180/π.

In this example we are going to see how to use/call Math.toDegrees() method in java.

Output:

Explanation:

  • In above code we have simply converted angle in radian to angle in degrees using Math.toDegrees() method of the Math class.
  • As we know, 3.14, which is roughly equal to π, is very close to 180 degrees.

What is Math toDegrees() in Java?

An angle measured in radians is converted to a roughly comparable angle measured in degrees using the Math.toDegrees() method.

  • This method will return NaN if the argument is NaN
  • This method will return zero with the same sign as the argument if the argument is zero.
  • This method will return Infinity with the same sign as the input if the argument is Infinity.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

More Examples

Example 1

In this example, we are going to see how to convert radians to degrees using toDegrees() method in Java:

Output:

Explanation:

  • In the above Example, we have converted the angle in radians to degrees using toDegrees() method in Java.
  • We have initialized x and y as 1.5708 and -0.0, and converted them into degrees.

Example 2

In this example, we are going to use toDegrees() method in java with NaN.

Output:

Explanation:

  • As we have discussed above that toDegrees() will return NaN when a NaN is passed as argument.

Note: Square of a negative number is NaN in Java.

Example-3

In this example, we are going to see how to use Math.toDegrees() in java with Infinity.

Output:

Explanation:

  • As we discussed above that this method will return Infinity with the same sign as the input if the argument is Infinity.
  • So in the above code Infinity is printed when POSITIVE_INFINITY is passed and -Infinity is printed when NEGATIVE_INFINITY is passed.

Conclusion

  • An angle measured in radians is converted to a roughly comparable angle measured in degrees using the toDegrees() method defined in Math class.
  • This method will return NaN if the argument is NaN.
  • This method will return zero with the same sign as the argument if the argument is zero.
  • This method will return Infinity with the same sign as the argument if the argument is Infinity.