Home »
Java programming language
Java Math Class static double toRadians(double angle_in_degrees) with example
Java Math Class static double toRadians(double angle_in_degrees) method: Here, we are going to learn about the static double toRadians(double angle_in_degrees) method of Math Class with its syntax and example.
Submitted by Preeti Jain, on September 09, 2019
Math Class static double toRadians(double angle_in_degrees)
- This method is available in java.lang package.
- This method is used to convert the angle from degrees to radians or in other words we can say this method is used to convert an angle measured in degrees to an equivalent angle measured in radians.
- This is a static method, it is accessible with the class name too.
- The return type of this method is double, it returns the converted angle from degrees to radians of double type.
- In this method, we pass only one parameter which represents an angle in the degrees form.
- This method does not throw any exception.
- The result of conversion an angle from degrees to radians is not generally exact.
Syntax:
public static double toRadians(double angle_in_degrees){
}
Parameter(s): angle_in_degrees – a ‘double’ type value which is an angel in the degrees.
Return value:
The return type of this method is double, it returns the converted value from degree to radians.
Java program to demonstrate example of toRadians(double angle_in_degrees) method
// Java program to demonstrate the example of
// toRadians(double angle_in_degrees) method of Math Class.
public class ToRadiansMethod {
public static void main(String[] args) {
// declaring the variables
double d1 = 60;
double d2 = -60;
double d3 = 90;
double d4 = -90;
// display the values
System.out.println("Angel values in degrees...");
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
// converting the values from degree to radians
d1 = Math.toRadians(d1);
d2 = Math.toRadians(d2);
d3 = Math.toRadians(d3);
d4 = Math.toRadians(d4);
System.out.println("Angel values in radians...");
System.out.println("d1: " + d1);
System.out.println("d2: " + d2);
System.out.println("d3: " + d3);
System.out.println("d4: " + d4);
}
}
Output
E:\Programs>javac ToRadiansMethod.java
E:\Programs>java ToRadiansMethod
Angel values in degrees...
d1: 60.0
d2: -60.0
d3: 90.0
d4: -90.0
Angel values in radians...
d1: 1.0471975511965976
d2: -1.0471975511965976
d3: 1.5707963267948966
d4: -1.5707963267948966