C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Operators & Expressions

Java Program: Evaluate Trigonometric Expressions (sin, cos, tan)

Expression Evaluated

Result = sin(θ) + cos(θ) + tan(θ)

import java.util.Scanner;

 

public class TrigonometricEvaluation {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter angle in degrees: ");

        double angle = sc.nextDouble();

 

        // Convert degrees to radians

        double radians = Math.toRadians(angle);

 

        // Trigonometric calculations

        double sinValue = Math.sin(radians);

        double cosValue = Math.cos(radians);

        double tanValue = Math.tan(radians);

 

        double result = sinValue + cosValue + tanValue;

 

        System.out.println("\n------ Trigonometric Evaluation ------");

        System.out.printf("sin(%.2f°) = %.4f%n", angle, sinValue);

        System.out.printf("cos(%.2f°) = %.4f%n", angle, cosValue);

        System.out.printf("tan(%.2f°) = %.4f%n", angle, tanValue);

        System.out.printf("Result = %.4f%n", result);

 

        sc.close();

    }

}

Output

 
INPUT :
Enter angle in degrees: 30

OUTPUT :
------ Trigonometric Evaluation ------
sin(30.00°) = 0.5000
cos(30.00°) = 0.8660
tan(30.00°) = 0.5774
Result = 1.9434

Explanation

  1. Why Convert Degrees to Radians?

Java’s Math class only works with radians, not degrees.

double radians = Math.toRadians(angle);

Java Programs

  1. Trigonometric Functions Used

Function

Description

Math.sin(x)

Calculates sine of angle

Math.cos(x)

Calculates cosine

Math.tan(x)

Calculates tangent

(All angles must be in radians.)

  1. Expression Evaluation

double result = sinValue + cosValue + tanValue;

  • Adds the computed trigonometric values.
  1. Output Formatting

System.out.printf("%.4f", value);

  • Displays values up to 4 decimal places for accuracy.

Key Concepts Used

Trigonometric functions
Degree-to-radian conversion
Mathematical expressions
Java Math class
Formatted output

📌 Short Exam Answer

This program evaluates trigonometric expressions using Java Math functions. The angle is converted from degrees to radians before computing sine, cosine, and tangent values.