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 Codepublicstaticvoidmain(String args[]){doubledegrees =45.0;// convert degrees to radiansdoubleradians = Math.toRadians(degrees);// sin() method to get the sine valuedoublesinValue = Math.sin(radians);// prints the sine valueSystem.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 Codepublicstaticvoidmain(String args[]){doubledegrees =45.0;// convert degrees to radiansdoubleradians = Math.toRadians(degrees);// cos() method to get the cosine valuedoublecosValue = Math.cos(radians);// prints the cosine valueSystem.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 Codepublicstaticvoidmain(String args[]){doubledegrees =45.0;// convert degrees to radiansdoubleradians = Math.toRadians(degrees);// cos() method to get the tangent valuedoubletanValue = Math.tan(radians);// prints the tangent valueSystem.out.println("tan("+ degrees +") = "+ tanValue);}}Output:
tan(45.0) = 0.9999999999999999



