×

Java Programs

Java Practice

Java program to convert degree to radian using library method

Given a value in degree, we have to convert it into radian.
Submitted by Nidhi, on May 13, 2022

Problem statement

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

Java program to convert degree to radian using library method

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

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

import java.util.*;

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

    double degree = 0;

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

    double rad = Math.toRadians(degree);

    System.out.print("Radian is: " + rad);
  }
}

Output

Enter degree: 30
Radian is: 0.5235987755982988

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 degree of double type and read its value from the user using the nextDouble() method of the Scanner class. Then we converted the degree into radian using Math.toRadians() method and assigned the result to the variable rad and printed the result.

Java Math Class Programs »



Related Programs



Comments and Discussions!

Load comments ↻





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