
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Trigonometric Methods in Java
The java.lang.Math class contains methods for performing basic numeric operations such as the trigonometry, logarithm, etc.
The following are some of the methods.
Sr.No | Methods & Description |
---|---|
1 |
static double abs(double a) This method returns the absolute value of a double value. |
2 |
static float abs(float a) This method returns the absolute value of a float value. |
3 |
static int abs(int a) This method returns the absolute value of an int value. |
4 |
static long abs(long a) This method returns the absolute value of a long value. |
5 |
static double acos(double a) This method returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. |
6 |
static double asin(double a) This method returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2. |
Let us see an example of acos() method.
Example
public class Demo { public static void main(String args[]) { double val = Math.PI / 2; val = Math.toRadians(val); System.out.println("Math.acos(" + val + ") = " + Math.acos(val)); } }
Output
Math.acos(0.027415567780803774) = 1.5433773235341761
Let us see an example of asin() method.
Example
public class Demo { public static void main(String args[]) { double val = Math.PI / 2; val = Math.toRadians(val); System.out.println("Math.asin(" + val + ") = " + Math.asin(val)); } }
Output
Math.asin(0.027415567780803774) = 0.02741900326072046
Let us see an example of log() method.
Example
public class Demo { public static void main(String args[]) { double val1 = 39564.9; double val2 = 1; System.out.println("Math.log(" + val1 + ") = " + Math.log(val1)); System.out.println("Math.log(" + val2 + ") = " + Math.log(val2)); } }
Output
Math.log(39564.9) = 10.585697640553684 Math.log(1.0) = 0.0
Advertisements