Home » Java programming language

Java StrictMath toRadians() Method with Example

StrictMath Class toRadians() method: Here, we are going to learn about the toRadians() method of StrictMath Class with its syntax and example.
Submitted by Preeti Jain, on December 27, 2019

StrictMath Class toRadians() method

  • toRadians() method is available in java.lang package.
  • toRadians() method is used to convert the angle from degrees to radians or in other words this method is used to convert an angle measured in degrees to an equivalent angle measured in radians.
  • toRadians() method is a static method so it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
  • toRadians() method does not throw any exception at the time of conversion of an angle from degree to radians.
  • The result of conversion an angle from degrees to radians is not generally exact.

Syntax:

    public static double toRadians(double ang_in_deg);

Parameter(s):

  • double ang_in_deg – represents an angle in degrees.

Return value:

The return type of this method is double – it returns the radians converted value of the given angle (in degrees).

Example:

// Java program to demonstrate the example of 
// toRadians(double ang_in_deg) method of StrictMath class.

public class ToRadians {
    public static void main(String[] args) {

        // Variable Declarations
        double d1 = 60;
        double d2 = -60;
        double d3 = 90;
        double d4 = -90;

        // Display previous value of d1,d2,d3 and d4
        System.out.println("d1: " + d1);
        System.out.println("d2: " + d2);
        System.out.println("d3: " + d3);
        System.out.println("d4: " + d4);

        // By using toRadians() method is used to convert the given angle
        // from degrees into radians

        d1 = StrictMath.toRadians(d1);
        d2 = StrictMath.toRadians(d2);
        d3 = StrictMath.toRadians(d3);
        d4 = StrictMath.toRadians(d4);

        System.out.println("StrictMath.toRadians(d1): " + d1);
        System.out.println("StrictMath.toRadians(d2): " + d2);
        System.out.println("StrictMath.toRadians(d3): " + d3);
        System.out.println("StrictMath.toRadians(d4): " + d4);
    }
}

Output

d1: 60.0
d2: -60.0
d3: 90.0
d4: -90.0
StrictMath.toRadians(d1): 1.0471975511965976
StrictMath.toRadians(d2): -1.0471975511965976
StrictMath.toRadians(d3): 1.5707963267948966
StrictMath.toRadians(d4): -1.5707963267948966



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.