Java Math toRadians() Method

java math toRadains() Method

Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs() etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the math toRadains() Method in java.

Java Math toRadains() Method :

In Java, the Math.toRadians(double angdeg) method converts an angle in degrees to an approximately equivalent angle in radians.

The method takes a single parameter, angdeg, which is the angle in degrees. It returns a double value representing the angle in radians.Here’s an example of syntax how to use the toRadians() method:

Syntax  :

public static double toRadians(double angdeg)

Example 1 :  

Run
public class Main{
    public static void main(String[] args) {
    // Declare three angles in degrees
    double angle1 = 30.0;
    double angle2 = 60.0;
    double angle3 = 90.0;
    
    // Convert each angle to radians using Math.toRadians()
    double radians1 = Math.toRadians(angle1);
    double radians2 = Math.toRadians(angle2);
    double radians3 = Math.toRadians(angle3);
    
    // Print the results to the console
    System.out.println(radians1); // prints 0.5235987755982988
    System.out.println(radians2); // prints 1.0471975511965976
    System.out.println(radians3); // prints 1.5707963267948966
    }
}

Output :

0.5235987755982988
1.0471975511965976
1.5707963267948966

Example 2:  

Run
public class Main {
    public static void main(String[] args) {
    // Declare four angles in degrees
    double angle1 = 0.0;
    double angle2 = 45.0;
    double angle3 = 180.0;
    double angle4 = 270.0;
    
    // Convert each angle to radians using Math.toRadians()
    double radians1 = Math.toRadians(angle1);
    double radians2 = Math.toRadians(angle2);
    double radians3 = Math.toRadians(angle3);
    double radians4 = Math.toRadians(angle4);
    
    // Print the results to the console
    System.out.println(radians1); // prints 0.0
    System.out.println(radians2); // prints 0.7853981633974483
    System.out.println(radians3); // prints 3.141592653589793
    System.out.println(radians4); // prints 4.71238898038469
    }
}

Output :

0.0
0.7853981633974483
3.141592653589793
4.71238898038469

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription