Trigonometric Functions in Java with Examples

The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
- Java.lang.Math.sin() Method : is an inbuilt method which returns the sine of the value passed as an argument. The value passed in this function should be in radians. If the argument is NaN or an infinity, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument.
Syntax :
Math.sin(double radians)
Parameters :
The method takes one mandatory argument in radians.Returns :
It returns a double value. The returned value is the sine of the specified double value passed.Example 1 : Program demonstrating the use of sin()
// Java program for sin() methodimportjava.util.*;ÂÂclassGFG {   Â// Driver Code   Âpublicstaticvoidmain(String args[])   Â{       Âdoubledegrees =45.0;       Â// convert degrees to radians       Âdoubleradians = Math.toRadians(degrees);       Â// sin() method to get the sine value       ÂdoublesinValue = Math.sin(radians);       Â// prints the sine value       ÂSystem.out.println("sin("+ degrees +") = "+ sinValue);   Â}}Output:
sin(45.0) = 0.7071067811865475
- Java.lang.Math.cos() : is an inbuilt method which returns the cosine of the value passed as an argument. The value passed in this function should be in radians. If the argument is NaN or an infinity, then the result is NaN.
Syntax :
Math.cos(double radians)
Parameters :
The method takes one mandatory argument in radians.Returns :
It returns a double value. The returned value is the cosine of the specified double value passed.Example 2 : Program demonstrating the use of cos()
// Java program for cos() methodimportjava.util.*;ÂÂclassGFG {   Â// Driver Code   Âpublicstaticvoidmain(String args[])   Â{       Âdoubledegrees =45.0;       Â// convert degrees to radians       Âdoubleradians = Math.toRadians(degrees);       Â// cos() method to get the cosine value       ÂdoublecosValue = Math.cos(radians);       Â// prints the cosine value       ÂSystem.out.println("cos("+ degrees +") = "+ cosValue);   Â}}Output:
cos(45.0) = 0.7071067811865476
- Java.lang.Math.tan() : is an inbuilt method which returns the tangent of the value passed as an argument. The value passed in this function should be in radians. If the argument is NaN or an infinity, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument.
Syntax :Math.tan(double radians)
Parameters :
The method takes one mandatory argument in radians.Returns :
It returns a double value. The returned value is the tangent of the specified double value passed.Example 3 : Program demonstrating the use of tan()
// Java program for tan() methodimportjava.util.*;ÂÂclassGFG {   Â// Driver Code   Âpublicstaticvoidmain(String args[])   Â{       Âdoubledegrees =45.0;       Â// convert degrees to radians       Âdoubleradians = Math.toRadians(degrees);       Â// cos() method to get the tangent value       ÂdoubletanValue = Math.tan(radians);       Â// prints the tangent value       ÂSystem.out.println("tan("+ degrees +") = "+ tanValue);   Â}}Output:
tan(45.0) = 0.9999999999999999



