How to used Trigonometric function in java with example

Math class method is used for Trigonometric function in java. Trigonometric function like cosine, sine hyperbolic sine, arc sine can be used in java using math class methods

Syntax:-

Math.method(Variable)

method can be replaced by any Trigonometric function

List Trigonometric function used in java

Method Operation Datatype used
Math.sin(variable) sine Double
Math.cos(variable) cosine Double
Math.tan(variable) tan Double
Math.sinh(variable) hyperbolic sine Double
Math.cosh(variable) hyperbolic cosin Double
Math.tanh(variable) hyperbolic tan Double
Math.asin(variable) arc sine Double
Math.acos(variable) arc cosine Double
Math.atan(variable) arc tan Double

Convert radians to degrees in java

Syntax:-

toDegrees(variable)

toDegrees Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

Convert degrees to radians in java

Syntax:-

toRadians(variable)

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

Example:-

import java.util.Scanner;

class group{
public static void main(String angt[]){
Scanner data = new Scanner(System.in);
double num,num1;
System.out.println("Enter a number");
num1=data.nextDouble();

num=Math.cos(num1);
System.out.println("Answer:"+num);

num=Math.sinh(num1);
System.out.println("Answer:"+num);

num=Math.atan(num1);
System.out.println("Answer:"+num);
num=Math.toDegrees(num1);
System.out.println("Answer:"+num);

}
}

Output:-

Enter a number
2
Answer:-0.4161468365471424
Answer:3.626860407847019
Answer:1.1071487177940904
Answer:114.59155902616465



Previous Code:-
Logarithm function in java

List Code:-
Java codes

Next Code:-


Java Programs:-
List of Java Programs

5 Comments

Add your comments here

Back to Top