# Java Math cos() Function ## Java Math Class

Java Math class provides several methods to perform several operations on math calculations like max(), min(), sin(), cos(), round(), ceil(), floor(), abs() etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the cos() Method in java.

## Java cos Function :

Java Collection contains Math class and The class Math contains methods for performing basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.

The cos Function of math class in Java returns the trigonometric cosine of the input angle. It is a static function so we can access it by using the Math class.

#### Syntax:

`Math.cos(number);`

#### Example :

Run
```import java.util.*;

public class Main{
public static void main(String[] args){
// Initializing variables in Degree
int a = 0;
int b = 45;

// Using cos Function
double cosa = Math.cos(a);
double cosb = Math.cos(b);

// Printing Values of Variables
System.out.println("Cos Value For angle a : " + cosa);
System.out.println("Cos Value For angle b : " + cosb);
}
}```
```Output:

Cos Value For angle a : 1.0
Cos Value For angle b : 0.5253219888177297```

In the above Example, We had taken two variables with two different angles stored in them. we need to store the cos values of the given angles in variables of double data type.

#### Example:

Run
```import java.util.*;

public class Main{
public static void main(String[] args){
// Initializing variables in Degree
int a = 0;
int b = 60;

// printing cosine values
System.out.println("Cos value of a : " + Math.cos(radiana));
System.out.println("Cos value of b : " + Math.cos(radianb));
}
}```
```Output:

Cos value of a : 1.0
Cos value of b : 0.5000000000000001```

In the above Example, We had converted the given angle into radians because  as per the official documentation of Java, the cos() method takes the angle as radians.

### Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

## Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others