Java toRadians() method with Example


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.

Example

Here, the angdeg method is an angle, in degrees. Let us now see an example −

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));
   }
}

Output

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

Example

Let us see another example −

import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      double x = 90.0;
      double y = 30.0;
      // 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));
   }
}

Output

Math.tanh(1.5707963267948966)=0.9171523356672744
Math.tanh(0.5235987755982988)=0.4804727781564516
raja
Published on 25-Sep-2019 08:43:43
Advertisements