Java - Math toRadians() Method



Description

The Java Math toRadians(double angdeg) converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Syntax

public static double toRadians(double d)

Parameters

Here is the detail of parameters −

  • d − A double data type.

Return Value

  • This method returns a double value.

Example 1

In this example, we're showing the usage of Math.toRadians() method to get the radians of two double numbers. We've created two double variables x and y and initialized them with a given values. Then using Math.toRadians() method we've printed the corresponding radian values.

public class Test { 
   public static void main(String args[]) {
      double x = 45.0;
      double y = 30.0;

      System.out.println( Math.toRadians(x) );
      System.out.println( Math.toRadians(y) );
   }
}

This will produce the following result −

Output

0.7853981633974483
0.5235987755982988

Example 2

In this example, we're showing the usage of Math.toRadians() method to get the degrees of two float numbers. We've created two float variables x and y and initialized them with a given values. Then using Math.toRadians() method we've printed the corresponding radian values.

public class Test { 
   public static void main(String args[]) {
      float x = (float)45.0;
      float y = (float)30.0;

      System.out.println( Math.toRadians(x) );
      System.out.println( Math.toRadians(y) );
   }
}

This will produce the following result −

Output

0.7853981633974483
0.5235987755982988

Example 3

In this example, we're showing the usage of Math.toRadians() method to get the radians of a zero value. We've created two float variables x and y and initialized them with a given values. Then using Math.toRadians() method we've printed the corresponding degree values.

public class Test { 
   public static void main(String args[]) {
      float x = (float)0.0;
      float y = (float)-0.0;

      System.out.println( Math.toRadians(x) );
      System.out.println( Math.toRadians(y) );
   }
}

This will produce the following result −

Output

0.0
-0.0
java_numbers.htm
Advertisements