# 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.

1. 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() method ` `import` `java.util.*; ` ` `  `class` `GFG { ` ` `  `    ``// Driver Code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` ` `  `        ``double` `degrees = ``45.0``; ` ` `  `        ``// convert degrees to radians ` `        ``double` `radians = Math.toRadians(degrees); ` ` `  `        ``// sin() method to get the sine value ` `        ``double` `sinValue = Math.sin(radians); ` ` `  `        ``// prints the sine value ` `        ``System.out.println(``"sin("` `+ degrees + ``") = "` `+ sinValue); ` `    ``} ` `} `

Output:

```sin(45.0) = 0.7071067811865475
```
2. 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() method ` `import` `java.util.*; ` ` `  `class` `GFG { ` ` `  `    ``// Driver Code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` ` `  `        ``double` `degrees = ``45.0``; ` ` `  `        ``// convert degrees to radians ` `        ``double` `radians = Math.toRadians(degrees); ` ` `  `        ``// cos() method to get the cosine value ` `        ``double` `cosValue = Math.cos(radians); ` ` `  `        ``// prints the cosine value ` `        ``System.out.println(``"cos("` `+ degrees + ``") = "` `+ cosValue); ` `    ``} ` `} `

Output:

```cos(45.0) = 0.7071067811865476
```
3. 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() method ` `import` `java.util.*; ` ` `  `class` `GFG { ` ` `  `    ``// Driver Code ` `    ``public` `static` `void` `main(String args[]) ` `    ``{ ` ` `  `        ``double` `degrees = ``45.0``; ` ` `  `        ``// convert degrees to radians ` `        ``double` `radians = Math.toRadians(degrees); ` ` `  `        ``// cos() method to get the tangent value ` `        ``double` `tanValue = Math.tan(radians); ` ` `  `        ``// prints the tangent value ` `        ``System.out.println(``"tan("` `+ degrees + ``") = "` `+ tanValue); ` `    ``} ` `} `

Output:

```tan(45.0) = 0.9999999999999999
```

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up Striver(underscore)79 at Codechef and codeforces D

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : ShubhamMaurya3

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.