Java Math toDegrees() Method

java math todegrees() Method

Java Math Class

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)

 

Example 1 :  

Run

public class Main {
  public static void main(String[] args) {
    // Convert 0.5 radians to degrees
    double radians = 0.5;
    double degrees = Math.toDegrees(radians);
    System.out.println(degrees); // Outputs: 28.64788975654116

    // Convert 1.0 radians to degrees
    radians = 1.0;
    degrees = Math.toDegrees(radians);
    System.out.println(degrees); // Outputs: 57.29577951308232

    // Convert 1.5 radians to degrees
    radians = 1.5;
    degrees = Math.toDegrees(radians);
    System.out.println(degrees); // Outputs: 85.94366926962393

    // Convert 2.0 radians to degrees
    radians = 2.0;
    degrees = Math.toDegrees(radians);
    System.out.println(degrees); // Outputs: 114.59155902616465
  }
}

Output :

28.64788975654116
57.29577951308232
85.94366926962393
114.59155902616465

Example 2:  

Run
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

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription