In the previous article, we have seen Java Program to Convert an Angle in Radians to Degrees
In this article we are going to see how to convert angle from degree to radian using Java programming language.
Java Program to Convert an Angle in Degrees to Radians
Before Jumping into the program directly let’s see how to convert angle from degree to radian.
Explanation:
Radian: It is an angle with vertex at the center of a circle and its’ corresponding arc in the circle is equal to length of radius of the circle.
In Java we have built in math function in java.lang.Math class i.e. Math.toRadians()
method which converts an angle in degrees to approximately equivalent radians.
Let’s see different ways to convert angle from radian to degree.
Method-1: Java Program to Convert an Angle in Degrees to Radians By Using Math.toRadians() Method(Static Input)
Approach:
- Declare a double variable say
‘a’
and assign the value to it which is the degree value of an angle . - Now by using
Math.toRadians()
inbuilt method convert angle tp radians. - Print the result.
Program:
import java.util.*; import java.lang.Math; class Main { public static void main(String [] args) { //angle value declared double a = 180; //converting angle value to radians by using Math.toRadians() double radians = Math.toRadians(180); System.out.println("The converted radian value is:" + radians); } }
Output: The converted radian value is:3.141592653589793
Method-2: Java Program to Convert an Angle in Degrees to Radians By Using Math.toRadians() Method(Dynamic Input)
Approach:
- Declare a double variable say
‘a’
and take the value as user input which is the degree value of an angle . - Now by using
Math.toRadians()
inbuilt method convert angle tp radians. - Print the result.
Program:
import java.util.*; import java.lang.Math; class Main { public static void main(String [] args) { //Scanner class object created Scanner s = new Scanner(System.in); //taking degree value as user input System.out.println("Enter the degree value of an angle:"); double a = s.nextDouble(); //converting angle value to radians by using Math.toRadians() double radians = Math.toRadians(180); System.out.println("The converted radian value is:" + radians); } }
Output: Enter the degree value of an angle: 180 The converted radian value is:3.141592653589793
Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.
Related Java Programs: