Java Math toRadians()

toRadians() accepts double value as an argument, which is angle in degrees.

toRadians() computes the number of radians for the given degrees and returns the value as double datatype.

Following is the syntax of toRadians() method.

double radians = toRadians(double degrees)

Since the definition of toRadians() function has double datatype as argument, you can pass int, float or long as arguments as these datatypes will implicitly promote to double.

Example – Math.toRadians(double)

In the following example, we pass angle in radians as argument to toRadians() method and find the degrees for the given radians.

Java Program

public class MathExample {
	public static void main(String[] args) {
		double angle_degrees = 45;
		double angle_radians = Math.toRadians(angle_degrees);
		System.out.println(angle_radians);
	}
}

Output

0.7853981633974483
ADVERTISEMENT

Example – Math.toRadians(int)

In the following example, we pass an int value for the argument to toRadians() method.

Java Program

public class MathExample {
	public static void main(String[] args) {
		int angle_degrees = 45;
		double angle_radians = Math.toRadians(angle_degrees);
		System.out.println(angle_radians);
	}
}

Output

0.7853981633974483

Similarly, you can provide a float or long value as argument to toRadians() method.

Conclusion

In this Java Tutorial, we learned about Java Math.toRadians() function, with example programs.