Java program to convert radian to a degree using library method

Java example to convert radian to a degree using library method.
Submitted by Nidhi, on May 17, 2022

Problem Solution:

In this program, we will read a value in radian from the user using the Scanner class and convert it into the degree using the Math.toDegrees() method.

Program/Source Code:

The source code to convert radian to a degree using the library method is given below. The given program is compiled and executed successfully.

// Java program to convert radian to a degree 
// using library method

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(System.in);

    double radian = 0;

    System.out.print("Enter radian: ");
    radian = X.nextDouble();

    double degree = Math.toDegrees(radian);

    System.out.print("Degree is: " + degree);
  }
}

Output:

Enter radian: 3.14
Degree is: 179.9087476710785

Explanation:

In the above program, we imported the "java.util.*" package to use the Scanner class. Here, we created a public class Main that contains a main() method.

The main() method is the entry point for the program. And, created a variable radian of double type and read its value from the user using the nextDouble() method of the Scanner class. Then we converted the radian into a degree using the Math.toDegrees() method and assigned the result to the variable degree and printed the result.

Java Math Class Programs »



Related Programs




Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.