Convert radians to degrees java: In the previous article, we have seen Java Program to Find LCM of Two Numbers Using Euclid’s Algorithm
In this article we are going to see how to convert angle from radian to degree using Java programming language.
Java Program to Convert an Angle in Radians to Degrees
Before Jumping into the program directly let’s see how to convert angle from radian to degree.
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.toDegrees()
method which converts an angle in radians to approximately equivalent degrees.
Let’s see different ways to convert angle from radian to degree.
Method-1: Java Program to Convert an Angle in Radians to Degrees By Using Math.toDegrees() Method(Static Input)
Approach:
- Declare an double variable say
‘a’
and assign the value to it, which is the radial value of an angle . - Now by using
Math.toDegrees()
inbuilt method convert radians to angle. - Print the result.
Program:
import java.util.*; import java.lang.Math; class Main { public static void main(String [] args) { double a = 2; //converting radian to degree by using Math.toDegrees() double degrees = Math.toDegrees(2); System.out.println("The converted degree is:" + degrees); } }
Output: The converted degree is:114.59155902616465
Method-2: Java Program to Convert an Angle in Radians to Degrees By Using Math.toDegrees() Method(Dynamic Input)
Approach:
- Declare an double variable say
‘a’
and take the value of it as user input, which is the radial value of an angle . - Now by using
Math.toDegrees()
inbuilt method convert radians to angle. - 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); System.out.println("Enter the radial value of an angle:"); double a = s.nextDouble(); //converting radian to degree by using Math.toDegrees() double degrees = Math.toDegrees(2); System.out.println("The converted degree is:" + degrees); } }
Output: Enter the radial value of an angle: 2 The converted degree is:114.59155902616465
Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.
Related Java Programs: