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


This Java program takes an input value in radians from the user, converts it to degrees using the Math.toDegrees() method, and then prints the result to the console. Here's a step-by-step explanation of how the program works:

  • The java.util.Scanner class is imported to enable input from the user.
  • The public class Radian_Degree line declares a new public class named Radian_Degree.
  • The public static void main(String[] args) method is the entry point for the program. It takes an array of strings as input and returns nothing.
  • A new Scanner object is created and assigned to the variable input.
  • A double variable radian is declared and initialized to zero.
  • The System.out.print() method is used to display the prompt "Enter Radian Value : " to the user.
  • The input.nextDouble() method is used to read a double value from the user, which is stored in the radian variable.
  • The Math.toDegrees() method is used to convert the radian value to degrees, and the result is stored in the deg variable.
  • The System.out.print() method is used to display the result, which is the value of deg preceded by the string "Degree is : ".

Source Code

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

Output

Enter Radian Value : 23.55
Degree is : 1349.3156075330887

Example Programs