Programming Tutorials

toRadians() and toDegrees() Sample program in Java

By: Ivan Lim in Java Tutorials on 2007-09-12  

The toRadians() method converts degrees to radians. toDegrees() converts radians to degrees. Here is a program that demonstrates toRadians() and toDegrees():

// Demonstrate toDegrees() and toRadians().
class Angles {
    public static void main(String args[]) {
        double theta = 120.0;
        System.out.println(theta + " degrees is " +
                Math.toRadians(theta) + " radians.");
        theta = 1.312;
        System.out.println(theta + " radians is " +
                Math.toDegrees(theta) + " degrees.");
    }
}

The output is shown here.

120.0 degrees is 2.0943951023931953 radians.
1.312 radians is 75.17206272116401 degrees.





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)