Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs() etc. The java.lang.Math class contains various methods for performing basic numeric operations Here, in the page we will discuss about the math toDegrees() Method in java.
Java Math toDegrees() Method :
The Math.toDegrees(double angrad) method is a static method in the java.lang.Math class that converts an angle in radians to degrees. Or in another words it converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.
Syntax :
public static double toDegrees(double angrad)
Parameters :angrad - an angle, in radians
Throws Exception : It does throws any exceptions and error.
Return Value :The measurement of the angle angrad in degrees.
Explanation :In this example, we are converting four different values in radians to degrees using the Math.toDegrees method. The input values are 0.5, 1.0, 1.5, and 2.0 radians. The output values are 28.64788975654116, 57.29577951308232, 85.94366926962393, and 114.59155902616465 degrees, respectively.
public class Main {
public static void main(String[] args) {
// Convert PI/2 radians to degrees
double radians = Math.PI / 2;
double degrees = Math.toDegrees(radians);
System.out.println(degrees); // Outputs: 90.0
// Convert PI radians to degrees
radians = Math.PI;
degrees = Math.toDegrees(radians);
System.out.println(degrees); // Outputs: 180.0
// Convert 3 * PI/2 radians to degrees
radians = 3 * Math.PI / 2;
degrees = Math.toDegrees(radians);
System.out.println(degrees); // Outputs: 270.0
// Convert 2 * PI radians to degrees
radians = 2 * Math.PI;
degrees = Math.toDegrees(radians);
System.out.println(degrees); // Outputs: 360.0
}
}
Output :
90.0
180.0
270.0
360.0
Explanation :In this example, we are converting four different values in radians to degrees using the Math.toDegrees method. The input values are PI/2, PI, 3 * PI/2, and 2 * PI radians. The output values are 90.0, 180.0, 270.0, and 360.0 degrees, respectively.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment