Write a Java program to Find the trigonometric tangent of an angle


This Java program calculates the trigonometric tangent of an angle in degrees using the Math class. Here is a brief explanation of each part of the code:

  • import java.util.*; : This line imports all the classes from the java.util package, which includes the Scanner class that is used to read input from the user.
  • public class Trigonometric_Tangent: This line defines a public class called Trigonometric_Tangent. The name of the class must match the name of the file.
  • public static void main(String[] args) : This line defines the main method, which is the entry point of the program. The args parameter is an array of strings that contains any command-line arguments passed to the program.
  • Scanner input = new Scanner(System.in); : This line creates a new Scanner object called input, which is used to read input from the user.
  • double deg = 0; : This line declares a double variable called deg and initializes it to 0.
  • System.out.print("Enter The Degree : ");: This line displays a prompt to the user to enter the degree of the angle.
  • deg = input.nextDouble();: This line reads a double value entered by the user and assigns it to the deg variable.
  • double rad = Math.toRadians(deg); : This line converts the angle from degrees to radians using the Math.toRadians() method and assigns it to the rad variable.
  • System.out.print("Trigonometric Tangent is : " + Math.tan(rad));: This line calculates the trigonometric tangent of the angle in radians using the Math.tan() method and displays the result to the user.

Source Code

import java.util.*;
public class Trigonometric_Tangent
{
	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("Trigonometric Tangent is : " + Math.tan(rad));
	}
}

Output

Enter The Degree : 190
Trigonometric Tangent is : 0.1763269807084651

Example Programs