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)
Parameters :angrad - an angle, in radians
Throws Exception : Does not throw any exception
Return Value :The measurement of the angle angrad in degrees.
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
}
}
Explanation :In the example code, we declare three variables, angle1, angle2, and angle3, and assign them the values 30.0, 60.0, and 90.0 degrees, respectively. These values represent angles in degrees.
We then use the Math.toRadians() method to convert each angle to radians and store the results in the variables radians1, radians2, and radians3. Finally, we print the values of these variables to the console using the System.out.println() method.
Explanation :In this example, we declare four variables, angle1, angle2, angle3, and angle4, and assign them the values 0.0, 45.0, 180.0, and 270.0 degrees, respectively. We then use the Math.toRadians() method to convert each angle to radians and store the results in the variables radians1, radians2, radians3, and radians4. Finally, we print the values of these variables to the console.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment