Syntax error Trigonometric methods in Java

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

 Live Demo

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

 Live Demo

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

 Live Demo

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
Updated on: 2020-06-26T09:04:16+05:30

458 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements