# StrictMath cos() Method in Java with Examples

All methods of java.lang.StrictMath class : Set 1, Set 2

The java.lang.StrictMath.cos() is an inbuilt method in Java which is used to return the cosine value of a given angle. The method returns NaN when the given argument is NaN or infinity.

Syntax:

`public static double cos(double num)`

Parameters: The method accepts one parameter num of double type and refers to the angle in radian whose cosine value is to be returned.

Return Value: The method returns the cosine of the argument.
Examples :

```Input: num = 62.0
Output: 0.6735071623235862

Input: num = 64.6
Output: -0.19607204956188945
```

Below programs illustrate the java.lang.StrictMath.cos() method:
Program 1:

 `// Java praogram to illustrate the ` `// java.lang.StrictMath.cos() ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `public` `static` `void` `main(String[] args) { ` ` `  `    ``double` `num1 = ``0.0``, num2= ``1.0` `, num3= ``64.6``; ` `     `  `    ``/* Returns trigonometric cosine of specified ` `    ``angle in radian*/`  `    ``double` `cosValue = StrictMath.cos(num1);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num1+``" = "` `+ cosValue); ` ` `  `    ``cosValue = StrictMath.cos(num2);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num2+``" = "` `+ cosValue); ` ` `  `    ``cosValue = StrictMath.cos(num3);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num3+``" = "` `+ cosValue);} ` `} `

Output:

```The cosine of 0.0 = 1.0
The cosine of 1.0 = 0.5403023058681398
The cosine of 64.6 = -0.19607204956188945
```

Program 2:

 `// Java praogram to illustrate the ` `// java.lang.StrictMath.cos() ` `import` `java.lang.*; ` ` `  `public` `class` `Geeks { ` ` `  `public` `static` `void` `main(String[] args) { ` ` `  `    ``double` `num1= -``62.0``, num2 = ``1.0``; ` `        ``double` `num3= (``45``*(Math.PI))/``180``; ` `     `  `    ``/* It returns the  cosine of specified ` `    ``angle in radian*/`  `    ``double` `cosValue = StrictMath.cos(num1);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num1+``" = "` `+ cosValue); ` `    ``cosValue = StrictMath.cos(num2);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num2+``" = "` `+ cosValue); ` `    ``cosValue = StrictMath.cos(num3);  ` `    ``System.out.println(``"The cosine of "``+ ` `                           ``num3+``" = "` `+ cosValue);} ` `} `

Output:

```The cosine of -62.0 = 0.6735071623235862
The cosine of 1.0 = 0.5403023058681398
The cosine of 0.7853981633974483 = 0.7071067811865476
```

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 lets make it a lil simple

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.

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.