Write a Java program to Convert degree to radian using library method


  • The first line imports the java.util package, which provides the Scanner class for taking input from the user.
  • The second line declares a public class called Degree_Radian.
  • The third line declares the main method, which is the entry point of the program.
  • The fourth line creates a new instance of the Scanner class and assigns it to a variable called input.
  • The fifth line declares a variable called deg and initializes it to 0.
  • The sixth line prints a message asking the user to enter a degree value.
  • The seventh line calls the nextDouble() method of the Scanner class to read in a double value from the user and assigns it to the deg variable.
  • The eighth line converts the deg value to radians using the Math.toRadians() method and assigns it to a new variable called rad.
  • The ninth line prints out the value of rad along with the message "Radian : ".

Source Code

import java.util.*;
public class Degree_Radian
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		double deg = 0;
 
		System.out.print("Enter The Degree : ");
		deg = input.nextDouble();
 
		double rad = Math.toRadians(deg);
		System.out.print("Radian : " + rad);
	}
}

Output

Enter The Degree : 160
Radian : 2.792526803190927

Example Programs