Java.lang.Math.toRadians() Method

Advertisements


Description

The java.lang.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.

Declaration

Following is the declaration for java.lang.Math.toRadians() method

public static double toRadians(double angdeg)

Parameters

  • angdeg -- an angle, in degrees

Return Value

This method returns the measurement of the angle angdeg in radians.

Exception

  • NA

Example

The following example shows the usage of lang.Math.toRadians() method.

package com.tutorialspoint;

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers numbers
      double x = 45;
      double y = -180;

      // convert them in radians
      x = Math.toRadians(x);
      y = Math.toRadians(y);

      // print the hyperbolic tangent of these doubles
      System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x));
      System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y));

   }
}

Let us compile and run the above program, this will produce the following result:

Math.tanh(0.7853981633974483)=0.6557942026326724
Math.tanh(-3.141592653589793)=-0.99627207622075



Advertisements
Advertisements