java.lang.Math toRadians(double angdeg)

Description :

This java tutorial shows an example on how to use the toRadians(double angdeg) method of Math class under java.lang package. This method returns the equivalent in radians the value specified angle in degrees as method argument.

Method Syntax :

public static double toRadians(double angdeg)

Parameter Input :

DataType Parameter Description
double angdeg the angle in degrees to be converted in radians

Method Returns :

The toRadians(double a) method simply returns the radians equivalent of the degrees declared as method argument.

Compatibility Version :

Requires Java 1.0 and up

Exception :


Discussion :

The toRadians(double angdeg) method is static thus we should invoke it statically for example Math.toRadians(double angdeg). This method simply returns the equivalent in radians the angle method argument. We would be using this widely since the trigonometric functions of Math class usually takes radians as an input which is very much different in real life applications since angles is usually represented in degrees.

Java Code Example :

This java example source code demonstrates the use of toRadians method of Math class. Basically we just convert the angle taken from the user input into radians.


import static java.lang.System.*;

import java.util.Scanner;

 * This example source code demonstrates the use of 
 * toRadians(double angdeg) method of Math class

public class MathToRadians {

	public static void main(String[] args) {
		// ask for user input
		out.print("Enter angle in degrees:");
		Scanner scan = new Scanner(;
		// use scanner to get user console input
		double degrees = scan.nextDouble();		
		// convert the angle from degrees to radians 
		double radians = Math.toRadians(degrees);		
		out.println(degrees +" degress = "+radians +" radians");
		// close the scanner object to avoid memory leak



Sample Output :

Running the toRadians(double angdeg) method example source code of Math class will give you the following output

Enter angle in degrees:120
120.0 degress = 2.0943951023931953 radians

Exception Scenario :


Similar Method :

  • N/A

Suggested Reading List :

References :